17

I would like to install the plyr package from a .tar.gz file, into my library of R packages on a linux machine. How would I go about doing this? Do I just place it in the library directory? What if I do not have write permissions?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
kimmyjo221
  • 685
  • 4
  • 10
  • 17

3 Answers3

34

In the command line:

R CMD INSTALL <package-name>.tar.gz

Or in R:

install.packages(<pathtopackage>, repos = NULL, type="source")
EDi
  • 13,160
  • 2
  • 48
  • 57
  • please dont forget the quotes "". Hence, it is install.packages("", repos = NULL, type="source") Thanks for sharing – A1aks May 11 '20 at 19:08
  • I was getting the following error: "install: missing destination file operand after .tar.gz" This was resolved by typing "INSTALL" in CAPITAL LETTERS instead of just "install." – Brunox13 Aug 27 '20 at 13:23
11

From the command line,

R CMD INSTALL plyr_x.y.z.tar.gz

If you don't have permission to write to the standard library directory and can't use sudo to override, you can install it somewhere else via

R CMD INSTALL -l <user_lib> plyr_x.y.z.tar.gz

where <user_lib> is a directory you can write to. You may need to specify lib.loc when subsequently loading the package, if <user_lib> is not in .libPaths (see @DWin's answer).

See http://cran.r-project.org/doc/manuals/R-admin.html for more information; R CMD INSTALL --help may also be useful, albeit terse.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
3

If you do not have permissions to the default installed library you can add to the search path that R uses with .libPaths which "gets/sets the library trees within which packages are looked for."

.libPaths()  # will display all current libraries
?.libPaths

The second argument to install.packages (after the name of your plyr.version.tar.gz file) could be a user-controlled library directory.

?install.packages

I was a bit puzzled by first asking about installing from CRAN and then asking about installing a tar.gz file from which I formed the impression that you had already downloaded the file and were hoping to install it.

IRTFM
  • 258,963
  • 21
  • 364
  • 487