How to specify lib directory when installing development version R Packages from github repository

你说的曾经没有我的故事 提交于 2019-11-28 05:21:48

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

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/"

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!