gpt4 book ai didi

r - Ubuntu 在 R 中删除 .libPaths()

转载 作者:IT王子 更新时间:2023-10-29 00:31:36 25 4
gpt4 key购买 nike

安装 RStudio 后,我运行:

library()

Warning message: libraries '/usr/local/lib/R/site-library', 'usr/lib/R/site-library' contain no packages

然后我输入:

.libPaths()

[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"

如何删除 [2] 和 [3] 以防止警告消息再次出现?

预期输出:

.libPaths()

[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[4] "/usr/lib/R/library"

最佳答案

Linux

首先要做的是阅读它的联机帮助页 (?.libPaths),您会看到:

'.libPaths' is used for getting or setting the library trees that R knows about (and hence uses when looking for packages). If called with argument ‘new’, the library search path is set to the existing directories in unique(c(new, .Library.site, .Library)) and this is returned. If given no argument, a character vector with the currently active library trees is returned.

(强调)。这应该让我们想知道 .Library.site 包含什么。奇怪的是,它拥有“应该”始终保留的系统范围(ergo“站点”)库路径,因此它们始终得到维护。

它进一步说:

'.Library.site' can be set via the environment variable 'R_LIBS_SITE' (as a non-empty semicolon-separated list of library trees).

因此修复它的一种方法是在启动 R 时给它一个空字符串(不能在 R 中完成):

# in bash on the command line:
$ R_LIBS_SITE=" " R

# in R
R> .libPaths()
[1] "/usr/lib/R/library"

让它与 RStudio 一起工作的方法是创建一个至少包含以下内容的 ~/.Renviron 文件:

R_LIBS_SITE=" "

完成后,您不必再做任何事情来从 .libPaths() 中删除辅助站点库路径:

R> .libPaths()
[1] "/usr/lib/R/library"

window

假设您正在执行以下操作:

R> .libPaths(c("/home/avalon/R/x86_64-pc-linux-gun-library/3.2", .libPaths()))
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"

如果您想在完成此操作后更正它,则只需执行以下操作:

R> .libPaths( c(.libPaths()[c(1,4)]) )
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/lib/R/library"

或者,您可以第一次这样做(即,当它仍然具有三个元素时,其中两个对您不利):

R> .libPaths(c("/home/avalon/R/x86_64-pc-linux-gun-library/3.2", .libPaths()[3]))
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/lib/R/library"

当然有一种方法可以通过编程方式过滤路径,而不是盲目地获取第三个元素,但目前应该可行。

关于r - Ubuntu 在 R 中删除 .libPaths(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38241122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com