简体   繁体   English

R install.packages 返回“无法创建锁定目录”

[英]R install.packages returns "failed to create lock directory"

I get this error when downloading the Rcpp package:下载 Rcpp 包时出现此错误:

> install.packages("Rcpp", dependencies=TRUE)
Installing package(s) into ‘/home/me/src/Rlibs’ (as ‘lib’ is unspecified)
trying URL 'http://cran.us.r-project.org/src/contrib/Rcpp_0.10.2.tar.gz'
Content type 'application/x-gzip' length 2380089 bytes (2.3 Mb)
...
Warning in dir.create(lockdir, recursive = TRUE) :
  cannot create dir '/home', reason 'Permission denied'
ERROR: failed to create lock directory ‘/home/me/src/Rlibs/00LOCK-Rcpp’
...

As my machine is on a computer cluster, I've tried it on different nodes, and I was careful to delete the temporary files downloaded in /tmp.由于我的机器在一个计算机集群上,所以我在不同的节点上尝试过,我小心地删除了/tmp中下载的临时文件。 What is strange is that I have rights to write in /home/me/src/Rlibs/.奇怪的是,我有权在 /home/me/src/Rlibs/ 中写入。 So my questions are:所以我的问题是:

  1. why does R want to have writing rights in /home while it only needs writing rights in /home/me/?为什么 R 想要在 /home 中有写权而它只需要在 /home/me/ 中的写权?
  2. how can I fix the error?我该如何修复错误?

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
loaded via a namespace (and not attached):
[1] tools_2.15.2

On NFS file systems it is sometimes not obvious what things you have to close.在 NFS 文件系统上,有时需要关闭哪些内容并不明显。

The best way to avoid this is to use the --no-lock argument on the command line, ie:避免这种情况的最好方法是在命令行上使用--no-lock参数,即:

R CMD INSTALL --no-lock <pkg>

From within R, you can do this from within your command using:在 R 中,您可以使用以下命令在命令中执行此操作:

install.packages("Rcpp", dependencies = TRUE, INSTALL_opts = '--no-lock')

This happens when your last package installation has interrupted abnormally.当您的上次软件包安装异常中断时,就会发生这种情况。 to fix this you should remove the locked file.要解决此问题,您应该删除锁定的文件。 For example Execute this command in R console:例如在 R 控制台中执行此命令:

unlink("/home/me/src/Rlibs/00LOCK-Rcpp", recursive = TRUE)

Hope this helps!希望这可以帮助!

The easiest way to avoid this issue is before installing any package run the line below避免此问题的最简单方法是在安装任何软件包之前运行以下行

options("install.lock"=FALSE)

Then try the install.packages("name_of_package") to install the package.然后尝试 install.packages("name_of_package") 安装包。 The 00LOCK error would not come. 00LOCK 错误不会出现。

This can happen when you are upgrading to a major version of the R as well.当您升级到 R 的主要版本时也会发生这种情况。 Some major upgrades require you to rebuild your packages, eg, R 4.0.一些重大升级需要您重新构建软件包,例如 R 4.0。 In my case, I had installed R using Homebrew, brew install R and maintained it for a long time, but when I upgraded to 4, I had to build the packages again and ran into this problem.就我而言,我使用 Homebrew brew install Rbrew install R并维护了很长时间,但是当我升级到 4 时,我不得不再次构建包并遇到了这个问题。

To resolve it, you need to make sure that Homebrew removes leftovers of your older R installation.要解决它,您需要确保 Homebrew 删除旧 R 安装的剩余部分。 In default setting, you can find them here, /usr/local/lib/R .在默认设置中,您可以在这里找到它们, /usr/local/lib/R I had instances of 3.5 , and 3.6 besides the rest of R's internal.除了 R 内部的其余部分之外,我还有3.53.6实例。 You can remove everything there, and install R again, and everything should work fine.您可以删除那里的所有内容,然后再次安装 R,一切都应该正常工作。 Or just remove the older version of R, and empty the 4.0 .或者只是删除旧版本的 R,并清空4.0 I recommend doing a clean install though.不过,我建议进行全新安装。

So, if you are maintaining your R using Homebrew and ran into this problem, here is how you fix it:因此,如果您使用 Homebrew 维护 R并遇到此问题,请按照以下方法解决:

brew uninstall R
rm -r /usr/local/lib/R
brew install R

I encountered a similar problem running windows 7:我在运行 Windows 7 时遇到了类似的问题:

Error in install.packages : ERROR: failed to lock directory 'D:\\Program Files\\R\\R-3.6.2\\library' for modifying. install.packages 中的错误:错误:无法锁定目录“D:\\Program Files\\R\\R-3.6.2\\library”以进行修改。

I solved this problem with below command in the R-console:我在 R 控制台中使用以下命令解决了这个问题:

unlink("D:\\\\Program Files\\\\R\\\\R-3.6.2\\\\library/00LOCK", recursive = TRUE)

Hope this help windows users...希望这可以帮助 Windows 用户...

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

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