简体   繁体   English

R:require(foo,lib.loc = bar)不会将lib.loc = bar转发给依赖项

[英]R: require(foo, lib.loc=bar) does not forward lib.loc=bar to dependencies

I have a separate library folder. 我有一个单独的库文件夹。 I installed ks as follows: 我安装了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'

Now, I want to load these packages. 现在,我想加载这些软件包。

> require(ks, lib.loc='packages')
Loading required package: ks
Failed with error:  'package 'KernSmooth' required by 'ks' could not be found'

That is, require finds ks but not KernSmooth - because it is not trying to load KernSmooth from packages . 也就是说, require查找ks但不查找KernSmooth因为它没有尝试从packages加载KernSmooth I can load it manually: 我可以手动加载它:

> 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 

I can try to require(ks, lib.loc='packages) again, but then it will tell me that the next package, misc3d is also not loaded yet. 我可以再次尝试require(ks, lib.loc='packages) ,但是它会告诉我下一个包misc3d也尚未加载。

Do I have to manually load all the dependencies from my library folder? 我是否必须从库文件夹中手动加载所有依赖项? I expected this to work automatically, ie if I require(foo, bar) , foo will also try to load its dependencies from bar . 我希望它可以自动工作,即如果我require(foo, bar)foo也将尝试从bar加载其依赖项。

The function .libPaths is used to get and set the paths where R looks for packages. 函数.libPaths用于获取和设置R查找软件包的路径。 If you do the following it should work just fine. 如果执行以下操作,则应该可以正常工作。

install.packages('ks', lib='packages')

.libPaths("packages")
require(ks)

In fact, if you plan on using "packages" a lot you can even set it before installing, which makes all your new packages go there by default. 实际上,如果您打算大量使用"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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 需要lib.loc和必需的基本软件包 - Require lib.loc and Required base packages 安装自定义程序包时,“lib.loc”中找不到库树 - No library trees found in 'lib.loc' when installing custom package 错误:package 或 loadNamespace 中“EGSEA”的命名空间加载失败(i,c(lib.loc,.libPaths()),versionCheck = vI[[i]]): - Error: package or namespace load failed for ‘EGSEA’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): loadNamespace 中的错误(j &lt;- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): - Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 在loadNamespace(j &lt;-i [[1L]],c(lib.loc,.libPaths()),versionCheck = vI [[j]])中,“ car”的“ Rcmdr”错误加载失败: - “Rcmdr” error load failed for ‘car’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): R 中的 Loc 函数? - Loc function in R? R:从文件导入foo为bar - R: from file import foo as bar R 等效于 python 的 loc 功能 - R equivalent of python's loc functionality R 中具有多个条件的 .loc 的等价物是什么? - What is the equivalent of .loc with multiple conditions in R? 通过R中的foo(x,bar)的第二个参数调用的泛型函数 - Generic function called via second argument of foo(x, bar) in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM