如何在Ubuntu上设置R_LIBS_SITE,以便在启动时为所有用户正确设置.libPaths()? [英] How do I set R_LIBS_SITE on Ubuntu so that .libPaths() is set properly for all users at startup?
问题描述
我正在建立一个群集,其中所有节点都可以访问/nfs/software
,因此install.packages()
的好位置应该在/nfs/software/R
下.如何设置R_LIBS_SITE
,使其自动成为所有用户R环境的一部分?我尝试添加到/etc/R/Renviron
中为R_LIBS_SITE给出的路径,但help(Startup)
说请勿更改'R_HOME/etc/Renviron'本身",由于R_HOME
扩展为Renviron.site
和Rprofile.site
文件中进行输入似乎没有达到预期的效果.我在这里想念什么?
I am setting up a cluster where all nodes have access to /nfs/software
, so a good place to install.packages()
would be under /nfs/software/R
. How do I set R_LIBS_SITE
so that this is automatically part of all users' R environment? I tried prepending to the path given for R_LIBS_SITE in /etc/R/Renviron
but help(Startup)
says "do not change ‘R_HOME/etc/Renviron’ itself", which I'm not sure is the same file since R_HOME
expands to /usr/lib/R
, but has no effect in any case. Making entries in the various Renviron.site
and Rprofile.site
files does not seem to have the desired effect. What am I missing here?
与此相关的还有其他一些问题(在此处和
Some other questions have danced around this (here and here, maybe others), but people seem to settle for having a user-specific library in their HOME
.
推荐答案
确保对要写入的目录具有所有者和/或组写入权限.
Make sure you have owner and/or group write permissions for the directory you want to write into.
对于/etc/R/Renviron
的本地替代,首选文件/etc/R/Renviron.site
.
The file /etc/R/Renviron.site
is the preferred choice for local overrides to /etc/R/Renviron
.
另一种方法是在安装软件包时简单地添加目录.我倾向于通过以下脚本在(bash而非R)外壳上执行此操作,该脚本源自littler包中的示例:
Another way is to simply ... impose the directory when installing packages. I tend to do that on the (bash rather than R) shell via this script derived from an example in the littler package:
$ cat bin/install.r
#!/usr/bin/env r
#
# a simple example to install one or more packages
if (is.null(argv) | length(argv)<1) {
cat("Usage: installr.r pkg1 [pkg2 pkg3 ...]\n")
q()
}
## adjust as necessary, see help('download.packages')
repos <- "http://cran.us.r-project.org"
#repos <- "http://cran.r-project.org"
## this makes sense on Debian where no packages touch /usr/local
lib.loc <- "/usr/local/lib/R/site-library"
install.packages(argv, lib.loc, repos)
,您可以轻松地为您的首选位置自定义这样的帮助程序.在~/bin/
中安装了脚本之后,我经常这样做
and you can easily customize a helper like this for your preferred location. With the script installed in ~/bin/
, I often do
$ ~/bin/install.r xts plyr doRedis
,它将忠实地安装这些软件包及其依赖文件. littler程序包具有类似的脚本update.r
.
and it will faithfully install these packages along with their depends. The littler package has a similar script update.r
.
这篇关于如何在Ubuntu上设置R_LIBS_SITE,以便在启动时为所有用户正确设置.libPaths()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!