问题:
非root权限下安装的R包都是默认安装在
/home/[yourname]/R/x86_64-pc-linux-gnu-library/[version]
这就导致一个问题,别的用户无法使用到你安装的包,需要自己再安装一遍,这样就很麻烦
解决办法:将别人的R library path 加载到自己的R环境变量中就可以了:
先查看一下包的安装路径:
.libPath()
[1] "/home/user2/R/x86_64-pc-linux-gnu-library/4.1"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"
安装时会按照顺序安装,
方法1:
.libPaths(new='/home/balter/conda/envs/dada2/lib/R/library')
.libPaths()
[1] "/home/balter/conda/envs/dada2/lib/R/library" "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library" "/usr/lib/R/library"
方法2:将别人的library 路径导入到自己的环境变量中,
export R_LIBS="/home/user2/R/x86_64-pc-linux-gnu-library/4.1"
即可凑合用。
更专业点就是修改R启动时候加载的Rprofile文件,参考:
https://www.cnblogs.com/jessepeng/p/10984983.html
将包安装到指定的path中:
args <- c("/xx/vdjtools/vdjtools-1.2.1/Rpackages/", "reshape2", "FField", "reshape", "gplots", "gridExtra", "circlize", "ggplot2", "grid", "VennDiagram", "RColorBrewer", "plotrix", "ape", "MASS", "scales")
libPath <- args[1]
# iterate over dependencies
for (i in 2:length(args)) {
# install packages to local library, use 0-Cloud mirror
# note that local library is set as default search path path by RUtil
install.packages(args[i], lib=libPath, repos="http://cran.rstudio.com/")
}
网友评论