你如何改变R中的库位置? [重复]

时间:2021-10-01 22:40:37

This question already has an answer here:

这个问题在这里已有答案:

Due to the new R 2.11 release, I want to implement Dirk's suggestion here.

由于新的R 2.11版本,我想在这里实现Dirk的建议。

So for that I am asking - How can I (permanently) change R's library path? (The best solution would be one that can be run from within R)

所以我要问 - 我怎样(永久)改变R的库路径? (最好的解决方案是可以在R内运行的解决方案)

4 个解决方案

#1


30  

You can edit Rprofile in the base library (in 'C:/Program Files/R.Files/library/base/R' by default) to include code to be run on startup. Append

您可以在基本库中编辑Rprofile(默认情况下在'C:/ Program Files / R.Files / library / base / R'中)以包含要在启动时运行的代码。附加

########        User code        ########
.libPaths('C:/my/dir')

to Rprofile using any text editor (like Notepad) to cause R to add 'C:/my/dir' to the list of libraries it knows about.

Rprofile使用任何文本编辑器(如记事本)使R将'C:/ my / dir'添加到它知道的库列表中。

(Notepad can't save to Program Files, so save your edited Rprofile somewhere else and then copy it in using Windows Explorer.)

(记事本无法保存到Program Files,因此请将已编辑的Rprofile保存在其他位置,然后使用Windows资源管理器将其复制。)

#2


14  

I've used this successfully inside R script:

我在R脚本中成功使用了这个:

library("reshape2",lib.loc="/path/to/R-packages/")

useful if for whatever reason libraries are in more than one place.

如果出于任何原因,库在多个地方都很有用。

#3


14  

This post is just to mention an additional option. In case you need to set custom R libs in your Linux shell script you may easily do so by

这篇文章只是提到一个额外的选择。如果您需要在Linux shell脚本中设置自定义R库,您可以轻松地执行此操作

export R_LIBS="~/R/lib"

See R admin guide on complete list of options.

有关选项的完整列表,请参阅R admin指南。

#4


4  

I'm late to the party but I encountered the same thing when I tried to get fancy and move my library and then had files being saved to a folder that was outdated:

我迟到了,但是当我试图想要移动我的库然后将文件保存到过时的文件夹时,我遇到了同样的事情:

.libloc <<- "C:/Program Files/rest_of_your_Library_FileName"

One other point to mention is that for Windows Computers, if you copy the address from Windows Explorer, you have to manually change the '\' to a '/' for the directory to be recognized.

还有一点要提到的是,对于Windows计算机,如果从Windows资源管理器复制地址,则必须手动将“\”更改为要识别的目录的“/”。

#1


30  

You can edit Rprofile in the base library (in 'C:/Program Files/R.Files/library/base/R' by default) to include code to be run on startup. Append

您可以在基本库中编辑Rprofile(默认情况下在'C:/ Program Files / R.Files / library / base / R'中)以包含要在启动时运行的代码。附加

########        User code        ########
.libPaths('C:/my/dir')

to Rprofile using any text editor (like Notepad) to cause R to add 'C:/my/dir' to the list of libraries it knows about.

Rprofile使用任何文本编辑器(如记事本)使R将'C:/ my / dir'添加到它知道的库列表中。

(Notepad can't save to Program Files, so save your edited Rprofile somewhere else and then copy it in using Windows Explorer.)

(记事本无法保存到Program Files,因此请将已编辑的Rprofile保存在其他位置,然后使用Windows资源管理器将其复制。)

#2


14  

I've used this successfully inside R script:

我在R脚本中成功使用了这个:

library("reshape2",lib.loc="/path/to/R-packages/")

useful if for whatever reason libraries are in more than one place.

如果出于任何原因,库在多个地方都很有用。

#3


14  

This post is just to mention an additional option. In case you need to set custom R libs in your Linux shell script you may easily do so by

这篇文章只是提到一个额外的选择。如果您需要在Linux shell脚本中设置自定义R库,您可以轻松地执行此操作

export R_LIBS="~/R/lib"

See R admin guide on complete list of options.

有关选项的完整列表,请参阅R admin指南。

#4


4  

I'm late to the party but I encountered the same thing when I tried to get fancy and move my library and then had files being saved to a folder that was outdated:

我迟到了,但是当我试图想要移动我的库然后将文件保存到过时的文件夹时,我遇到了同样的事情:

.libloc <<- "C:/Program Files/rest_of_your_Library_FileName"

One other point to mention is that for Windows Computers, if you copy the address from Windows Explorer, you have to manually change the '\' to a '/' for the directory to be recognized.

还有一点要提到的是,对于Windows计算机,如果从Windows资源管理器复制地址,则必须手动将“\”更改为要识别的目录的“/”。