我有一个单独的库文件夹。我按如下方式安装了ks
:
> install.packages('ks', lib='packages')
There is a binary version available (and will be
installed) but the source version is later:
binary source
ks 1.9.2 1.9.4
also installing the dependencies 'KernSmooth', 'misc3d', 'mvtnorm', 'rgl', 'multi cool'
现在,我想加载这些软件包。
> require(ks, lib.loc='packages')
Loading required package: ks
Failed with error: 'package 'KernSmooth' required by 'ks' could not be found'
也就是说,require
找到了ks
但未找到KernSmooth
- 因为它并未尝试从KernSmooth
加载packages
。我可以手动加载它:
> require(KernSmooth, lib.loc='packages')
Loading required package: KernSmooth
KernSmooth 2.23 loaded
Copyright M. P. Wand 1997-2009
Warning message:
package 'KernSmooth' was built under R version 3.1.2
我可以再次尝试require(ks, lib.loc='packages)
,但它会告诉我下一个包misc3d
尚未加载。
我是否必须手动加载库文件夹中的所有依赖项?我希望这会自动生效,即如果我require(foo, bar)
,foo
也会尝试从bar
加载其依赖项。
答案 0 :(得分:2)
函数.libPaths
用于获取和设置R查找的路径
包。如果您执行以下操作,它应该可以正常工作。
install.packages('ks', lib='packages')
.libPaths("packages")
require(ks)
事实上,如果你计划大量使用"packages"
,你甚至可以在安装之前设置它,这使得你的所有新包都默认存在。
.libPaths("packages")
.libPaths()
[1] "/home/christofer/packages" "/usr/local/lib/R/site-library" [3] "/usr/lib/R/site-library" "/usr/lib/R/library"
install.packages('ks')
Installing package into ‘/home/christofer/packages’ (as ‘lib’ is unspecified) ...
require(ks)