我想测试一下,我已经设置了我的包依赖项并正确导入。我认为最好的检查方法是使用新的R安装,但我不想删除所有现有的库来执行此测试。最简单的方法来测试R包安装在新鲜的R安装?
有没有一种相对无痛的方式来快速创建一个孤立的R实例只有基础库和测试安装?最好能够在我完成后轻松地将整个事情撕下来。
我想测试一下,我已经设置了我的包依赖项并正确导入。我认为最好的检查方法是使用新的R安装,但我不想删除所有现有的库来执行此测试。最简单的方法来测试R包安装在新鲜的R安装?
有没有一种相对无痛的方式来快速创建一个孤立的R实例只有基础库和测试安装?最好能够在我完成后轻松地将整个事情撕下来。
我已经安装在计算机上的蟒蛇/ miniconda,它可以被用来在我的机器上
conda create -n r-dev -c r r-essentials
不幸的是创造的R环境ElementaryOS Loki 0.4
。这并没有正确设置tk/tcl,运行conda install tk
, conda install tcl
没有帮助,结果是install.packages()
在搜索CRAN镜像时会失败。我只需要devtools所以解决方法是使用
conda install r-devtools
而且我需要Bioconductor的包,所以我需要
R>source("https://bioconductor.org/biocLite.R")
R>biocLite("BiocInstaller")
这样就完成了我所需要的环境,然后我用devtool::install_github()
来测试我的包的安装。
您可以(相当容易)恰当地使用“库路径” - 例如通过环境变量R_LIBS
和/或R_LIBS_USER
。其他选项是直接设置.libPaths()
。全部细节在help(Startup)
。
与没有附加依赖关系的包结合使用时应该这样做。
这是一个小小的演示,只需在当前环境中使用文件~/.Renviron
即可。我什么都没有,但“基地R”和它的包可见:
[email protected]:/tmp/libDemo$ cat .Renviron
R_LIBS=""
R_LIBS_USER=""
R_LIBS_SITE="/usr/lib/R/library"
[email protected]:/tmp/libDemo$ Rscript -e 'print(.libPaths())'
[1] "/usr/lib/R/library"
[email protected]:/tmp/libDemo$ Rscript -e 'print(installed.packages()[,1:2])'
Package LibPath
base "base" "/usr/lib/R/library"
boot "boot" "/usr/lib/R/library"
class "class" "/usr/lib/R/library"
cluster "cluster" "/usr/lib/R/library"
codetools "codetools" "/usr/lib/R/library"
compiler "compiler" "/usr/lib/R/library"
datasets "datasets" "/usr/lib/R/library"
foreign "foreign" "/usr/lib/R/library"
graphics "graphics" "/usr/lib/R/library"
grDevices "grDevices" "/usr/lib/R/library"
grid "grid" "/usr/lib/R/library"
KernSmooth "KernSmooth" "/usr/lib/R/library"
lattice "lattice" "/usr/lib/R/library"
MASS "MASS" "/usr/lib/R/library"
Matrix "Matrix" "/usr/lib/R/library"
methods "methods" "/usr/lib/R/library"
mgcv "mgcv" "/usr/lib/R/library"
nlme "nlme" "/usr/lib/R/library"
nnet "nnet" "/usr/lib/R/library"
parallel "parallel" "/usr/lib/R/library"
rpart "rpart" "/usr/lib/R/library"
spatial "spatial" "/usr/lib/R/library"
splines "splines" "/usr/lib/R/library"
stats "stats" "/usr/lib/R/library"
stats4 "stats4" "/usr/lib/R/library"
survival "survival" "/usr/lib/R/library"
tcltk "tcltk" "/usr/lib/R/library"
tools "tools" "/usr/lib/R/library"
utils "utils" "/usr/lib/R/library"
[email protected]:/tmp/libDemo$
如果你已经安装了anaconda python。您可以创建一个虚拟环境,隔离内容,您可以安装任何您喜欢的内容,然后通过卸载环境将其全部解散。 – sconfluentus
谢谢,我已经在研究这个或Docker,conda似乎更容易管理,但它并没有R的最新版本。 – shians
我的R安装在我的jupyter笔记本电脑环境中。它可能不是最近的,但它已经完成了我到目前为止所要求的所有内容...... – sconfluentus