简体   繁体   English

Ubuntu删除R中的.libPaths()

[英]Ubuntu remove .libPaths() in R

After I installed RStudio, I ran: 安装RStudio之后,我跑了:

library()

Warning message: libraries '/usr/local/lib/R/site-library', 'usr/lib/R/site-library' contain no packages 警告消息:库'/ usr / local / lib / R / site-library','usr / lib / R / site-library'不包含任何包

Then I input: 然后我输入:

.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"

How can I remove [2] and [3] to prevent the warning message appear again? 如何删除[2]和[3]以防止再次出现警告消息?

Expected output: 预期产量:

.libPaths()

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

Linux Linux的

First thing to do is read the manpage on it ( ?.libPaths ), and you'll see: 首先要做的是阅读它上面的联机帮助页( ?.libPaths ),你会看到:

'.libPaths' is used for getting or setting the library trees that R knows about (and hence uses when looking for packages). '.libPaths'用于获取或设置R知道的库树(因此在查找包时使用)。 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. 如果使用参数'new'调用,则库搜索路径将设置为unique(c(new, .Library.site, .Library))的现有目录,并返回此参数。 If given no argument, a character vector with the currently active library trees is returned. 如果没有给出参数,则返回具有当前活动库树的字符向量。

(emphasis added). (重点补充)。 This should clue us in to wonder what .Library.site holds. 这应该让我们想知道.Library.site是什么。 Oddly enough, it holds system-wide (ergo "site") library paths that "should" always be kept, so they are always maintained. 奇怪的是,它拥有“应该”始终保留的系统范围(ergo“站点”)库路径,因此它们始终保持不变。

It further goes on to say: 它进一步说:

'.Library.site' can be set via the environment variable 'R_LIBS_SITE' (as a non-empty semicolon-separated list of library trees). '.Library.site'可以通过环境变量'R_LIBS_SITE'设置(作为非空的以分号分隔的库树列表)。

So one way to fix it is to give it an empty string when you start R (cannot be done from within R): 所以解决它的一种方法是在启动R时给它一个空字符串(不能在R中完成):

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

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

The way to get this to work with RStudio is by creating a ~/.Renviron file with at least the following: 使用RStudio的方法是创建至少具有以下内容的~/.Renviron文件:

R_LIBS_SITE=" "

That done, you should not have to do anything further to remove the secondary site library paths from .libPaths() : 完成后,您不必再做任何事情来从.libPaths()删除辅助站点库路径:

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

Windows 视窗

Assuming you're doing the following: 假设您正在执行以下操作:

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"

If you want to correct it after you've done this, then just do: 如果你想在完成之后纠正它,那么就这样做:

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

Alternatively, you can do it this way the first time (ie, while it still has three elements, two of which are not good for you): 或者,你可以在第一次这样做(也就是说,它仍然有三个元素,其中两个对你不好):

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"

There is certainly a way to filter the paths programmatically instead of blindly taking the 3rd element, but this should work for now. 肯定有一种方法可以以编程方式过滤路径,而不是盲目地使用第3个元素,但这应该适用于现在。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM