我在Windows上运行R,不是作为管理员。当我安装一个包时,下面的命令不起作用:

> install.packages("zoo")
Installing package(s) into ‘C:/Program Files/R/R-2.15.2/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "C:/Program Files/R/R-2.15.2/library"' is not writable

要安装一个包,我必须指定一个库位置:

install.packages("zoo", lib="C:/software/Rpackages")

要加载一个包,我还必须指定库的位置:

library("zoo", lib.loc="C:/software/Rpackages")

所有这些都没问题,但我想看看是否可以将C:/software/Rpackages添加到库路径中,这样就不必每次都输入它了。

当我在网上搜索时,我发现这样做的一种方法是编辑Rprofile。站点文件并添加行

.libPaths("C:/software/Rpackages")

然而,在这样做并启动RStudio之后,这是我得到的输出

> .libPaths()
[1] "C:/Program Files/R/R-2.15.2/library" "C:/Program Files/RStudio/R/library" 

我添加到Rprofile的. libpaths命令。网站似乎没有任何效果!为什么会这样呢?或者更重要的是,如何解决这个问题,以便在不输入库位置的情况下安装和加载包?

注意:如果我启动RStudio, .libPaths()命令似乎可以正常工作

.libPaths("C:/software/Rpackages")
> .libPaths()
[1] "C:/software/Rpackages"               "C:/Program Files/R/R-2.15.2/library"

这不是很奇怪吗?


当前回答

只需将R库的默认文件夹更改为没有管理员权限的目录,例如:

.libPaths("C:/R/libs")

其他回答

在Ubuntu上,为用户更改默认库路径的推荐方法是在~/. conf中设置R_LIBS_USER变量。Renviron文件。

touch ~/.Renviron
echo "R_LIBS_USER=/custom/path/in/absolute/form" >> ~/.Renviron

我也遇到过同样的问题,我遇到了这个。如果你想创建另一个位置c(" c:/Users/mynewlocation")也应该可以工作。正如这里提到的“您应该能够右键单击Rstudio.exe图标,单击属性,并选择一个选项,始终以管理员身份运行Rstudio。当你想打开Rstudio时,一定要使用相同的图标。”

    myPaths <- .libPaths()   # get the paths
myPaths <- c(myPaths[2], myPaths[1])  # switch them
.libPaths(myPaths)  # reassign them

由于这里的大多数答案都与Windows和Mac OS有关,(考虑到我也在努力解决这个问题)我决定在Arch Linux安装中发布帮助我解决这个问题的过程。

步骤1:

Do a global search of your system (e.g. ANGRYSearch) for the term Renviron (which is the configuration file where the settings for the user libraries are set). It should return only two results at the following directory paths: /etc/R/ /usr/lib/R/etc/ NOTE: The Renviron config files stored at 1 & 2 (above) are hot-linked to each other (which means changes made to one file will automatically be applied [ in the same form / structure ] to the other file when the file being edited is saved - [ you also need sudo rights for saving the file post-edit ] ).

步骤2:

导航到第一个目录路径(/etc/R/),并用您最喜欢的文本编辑器打开Renviron文件。 进入Renviron文件后,搜索R_LIBS_USER标记,并将花括号部分中的文本更新为所需的目录路径。 例子: ... 更改来源(原始条目): R_LIBS_USER = $ {R_LIBS_USER - R ~ / / x86_64-pc-linux-gnu-library / 4.0 '} ... 更改到(您想要的条目): R_LIBS_USER = $ {R_LIBS_USER——“~ /应用程序/ R / rUserLibs '}

步骤3:

保存你刚刚编辑的Renviron文件……完成了! !

https://superuser.com/questions/749283/change-rstudio-library-path-at-home-directory

编辑~/。伦维隆

R_LIBS_USER=/some/path

如果您没有管理员权限,打开Rprofile也会很有帮助。站点文件位于\R-3.1.0\etc,并添加:

.First <- function(){
  .libPaths("your path here")
}

这将在开始时直接计算.libPath()命令