如何更改和删除默认库位置?

时间:2021-12-01 10:55:45

I am running R on a networked computer where I don't have write access to most locations on the C drive. However, my IT department decided to load the entire CRAN repository in the default library location on the C drive. I would strongly prefer to manage my packages on my own, and have a location on my networked drive I can install to, but I am trying to get R to ignore and forget the C drive location entirely.

我在联网计算机上运行R,我对C驱动器上的大多数位置没有写访问权限。但是,我的IT部门决定将整个CRAN存储库加载到C驱动器上的默认库位置。我非常希望自己管理我的软件包,并在我可以安装的网络驱动器上有一个位置,但我试图让R忽略并完全忘记C盘位置。

I have tried creating an .Rprofile file to set the library location, but no matter what I do, .libPaths() does not seem to forget the default location. I have tried the following:

我已经尝试创建.Rprofile文件来设置库位置,但无论我做什么,.libPaths()似乎都不会忘记默认位置。我尝试过以下方法:

.Library <- file.path("N:/My Documents/R/win-library/3.2")
.Library.site <- file.path("N:/My Documents/R/win-library/3.2")
.lib.loc <- file.path("N:/My Documents/R/win-library/3.2")
.libPaths(.libPaths())

Where the path on the N drive is the new location I want to be the only library path. But when I restart R and run .libPaths(), I still see this:

如果N驱动器上的路径是新位置,我想成为唯一的库路径。但是当我重新启动R并运行.libPaths()时,我仍然看到:

[1] "\\\\fileu/users$/username/My Documents/R/win-library/3.2"
[2] "C:/Program Files/R/R-3.2.4/library"

(On a side note, I'm trying to switch from the symbolic '\fileu' reference to a reference to the N drive.)

(另一方面,我正在尝试从符号'\ fileu'引用切换到对N驱动器的引用。)

I know there have been similar questions asked on this in the past (e.g., here), but the particular problem I'm having is that it's not forgetting the C drive location. I can't seem to erase that at all. Any help would be greatly appreciated!

我知道过去有过类似的问题(例如,这里),但我遇到的特殊问题是它不会忘记C盘的位置。我似乎根本无法抹去这一点。任何帮助将不胜感激!

2 个解决方案

#1


9  

Here be dragons.

这里是龙。

assign(".lib.loc", "\your\preferred\library", envir = environment(.libPaths))

#2


1  

If you want to change your library location permanently use this command: .libPaths("drive:/location/location")

如果要永久更改库位置,请使用以下命令:.libPaths(“drive:/ location / location”)

If you want to change your library location for the particular session in RStudio (i.e. for a temporary change), use: assign(".lib.loc", "drive:/location/location", envir = environment(.libPaths))

如果要更改RStudio中特定会话的库位置(即临时更改),请使用:assign(“。lib.loc”,“drive:/ location / location”,envir = environment(.libPaths))

#1


9  

Here be dragons.

这里是龙。

assign(".lib.loc", "\your\preferred\library", envir = environment(.libPaths))

#2


1  

If you want to change your library location permanently use this command: .libPaths("drive:/location/location")

如果要永久更改库位置,请使用以下命令:.libPaths(“drive:/ location / location”)

If you want to change your library location for the particular session in RStudio (i.e. for a temporary change), use: assign(".lib.loc", "drive:/location/location", envir = environment(.libPaths))

如果要更改RStudio中特定会话的库位置(即临时更改),请使用:assign(“。lib.loc”,“drive:/ location / location”,envir = environment(.libPaths))