2024-10-12 07:00:00

R在哪里存储包?

R中的install.packages()函数是用于在R中获取和安装包的自动解压缩实用程序。

如何找出R选择了哪个目录来存储包? 如何更改R存储和访问包的目录?


当前回答

感谢以上两位答题者的指导。詹姆斯·汤普森的建议最适合Windows用户。

Go to where your R program is installed. This is referred to as R_Home in the literature. Once you find it, go to the /etc subdirectory. C:\R\R-2.10.1\etc Select the file in this folder named Rprofile.site. I open it with VIM. You will find this is a bare-bones file with less than 20 lines of code. I inserted the following inside the code: # my custom library path .libPaths("C:/R/library") (The comment added to keep track of what I did to the file.) In R, typing the .libPaths() function yields the first target at C:/R/Library

注意:可能有不止一种方法来实现这一点,但由于某些原因,我尝试过的其他方法都不奏效。

其他回答

安装时附带的“R安装和管理”手册中记录了这一点。

在我的Linux机器上:

R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"      
[3] "/usr/lib/R/library"           
R> 

这意味着默认路径是第一个路径。你可以通过对INSTALL .packages()(从R内部)或R CMD INSTALL(在R外部)的参数来覆盖它。

也可以通过设置R_LIBS_USER变量来覆盖。

安装。packages命令查看. libpaths()变量。以下是我在OSX上的默认设置:

> .libPaths()
[1] "/Library/Frameworks/R.framework/Resources/library"

默认情况下我不会在那里安装包,我更喜欢将它们安装在我的主目录中。在我的.Rprofile中,我有这样一行:

.libPaths( "/Users/tex/lib/R" )

这将目录/Users/tex/lib/R添加到. libpaths()变量的前面。

感谢以上两位答题者的指导。詹姆斯·汤普森的建议最适合Windows用户。

Go to where your R program is installed. This is referred to as R_Home in the literature. Once you find it, go to the /etc subdirectory. C:\R\R-2.10.1\etc Select the file in this folder named Rprofile.site. I open it with VIM. You will find this is a bare-bones file with less than 20 lines of code. I inserted the following inside the code: # my custom library path .libPaths("C:/R/library") (The comment added to keep track of what I did to the file.) In R, typing the .libPaths() function yields the first target at C:/R/Library

注意:可能有不止一种方法来实现这一点,但由于某些原因,我尝试过的其他方法都不奏效。

你不需要'='

在Rprofile中使用. libpaths ("C:/R/library")。网站文件

确保你有正确的"符号(Shift-2)