35

In Ubuntu, I am installing all the R packages in the directory, /usr/lib/R/site-library by specifying lib option in install.packages().

But when I try to install the development version of the R packages using, install_github(), it always installs in a local repository of the system user.

.libPaths() has 4 directories including the local repository. So, I have 2 questions,

  1. Will it install in any of the other 3 repositories if i remove the local repository from .libPaths()?

  2. Is there any way to specify installation library path in install_github()?

I am using Ubuntu 12.04 64bit and R 3.0.1

----------------------UPDATE--------------------------------

  1. Unable to remove the local repository from .libPaths()

  2. If I try to install using install_github() in RStudio, it installs in the local repository since lib is not specified.

  3. If I try to install using install_github() as non-root user, it installs in the local repository since lib is not specified.

  4. If I try to install using install_github() as root user, it installs in the /usr/local/lib/R/site-library since lib is not specified.

Is there any to specify installation lib?

Manoj G
  • 1,776
  • 2
  • 24
  • 29

3 Answers3

55

To add specified library paths in devtools, we need to use with_libpaths()

Arguments for with_libpaths() are, with_libpaths(new, code)

Following is an example for using with_libpaths(),

library(devtools)
with_libpaths(new = "/usr/lib/R/site-library/", install_github('rCharts', 'ramnathv'))

Courtesy: Hadley, here :)

And other than with_libpaths(), there are more options for in devtools::with_something()

in_dir: working directory
with_collate: collation order
with_envvar: environmental variables
with_libpaths: library paths, replacing current libpaths
with_lib: library paths, prepending to current libpaths
with_locale: any locale setting
with_options: options
with_path: PATH environment variable
with_par: graphics parameters

More explanations here

Manoj G
  • 1,776
  • 2
  • 24
  • 29
  • 13
    `devtools::with_libpaths()` is deprecated. Use `withr::with_libpaths()`. See `help("devtools-deprecated")`. – swihart May 13 '16 at 01:35
  • This gives me `install: cannot create regular file ‘/usr/lib64/R/lib/libs3.so.2.0’: Permission denied make[1]: *** [install] Error 1 make[1]: Leaving directory `/mnt/tmp/RtmpShKPQi/devtools15aa419a91f09/AnalyticalFlavorSystems-RS3-536f287/src/libs3' make: *** [libs3.so] Error 2 ERROR: compilation failed for package ‘RS3’ * removing ‘/home/hadoop/git/threat-odin/lib/R/RS3’ Error: Command failed (1)` – d8aninja Apr 01 '17 at 00:03
  • As indicated above (but not explicitly stated), the correct syntax is `withr::with_libpaths(new=libPath, devtools::install_github('/') )` – mikemtnbikes Jul 21 '21 at 17:49
  • This works now: `remotes::install_github("/", lib="")`. – Alan Oct 27 '22 at 11:48
13

install_github takes a ... argument that passes to devtools::install. devtools::install has an args argument.

args
An optional character vector of additional command line arguments to be passed to R CMD install. This defaults to the value of the option "devtools.install.args".

R CMD install takes a library argument

 Options:
  -h, --help            print short help message and exit
  -v, --version         print INSTALL version info and exit
  -c, --clean           remove files created during installation
      --preclean        remove files created during a previous run
  -d, --debug           turn on debugging messages
                        and build a debug DLL
  -l, --library=LIB     install packages to library tree LIB

So the following should work:

devtools::install_github("repo", args = c('--library="./mypath/gdfgdg/"'))

however it doesnt appear to be replacing the call to R CMD install

"C:/PROGRA~1/R/R-31~1.0/bin/x64/R" --vanilla CMD INSTALL  \
  "C:\Users\john\AppData\Local\Temp\RtmpucrXMD/RSelenium_1.3.2.tar.gz"  \
  --library="C:/Users/john/Documents/R/win-library/3.1" --install-tests  \
  --library="C:/Users/john/Desktop/"
jdharrison
  • 30,085
  • 4
  • 77
  • 89
2

This is more of a workaround, but I found a way using the command-line version of R.

Starting from Ubuntu:

sudo -i R

the trick (I found) is to use -i option

Then from R:

.libPaths()

my local R directory does not appear; the default directory is the one that I want.

Then, I install.packages() or install_github() with impunity.

Hope this helps,

Ian

Ian Lyttle
  • 986
  • 7
  • 10
  • 1
    @lanLyttle: Thank you. But it still removes only local directory from `.libPaths()` and not there are 3 more directories. Same as running R as root user. – Manoj G Jul 10 '14 at 04:15