R install.packages returns "failed to create lock directory"
Solution 1
On NFS file systems it is sometimes not obvious what things you have to close.
The best way to avoid this is to use the --no-lock
argument on the command line, i.e.:
R CMD INSTALL --no-lock <pkg>
From within R, you can do this from within your command using:
install.packages("Rcpp", dependencies = TRUE, INSTALL_opts = '--no-lock')
Solution 2
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:
unlink("/home/me/src/Rlibs/00LOCK-Rcpp", recursive = TRUE)
Hope this helps!
Solution 3
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. The 00LOCK error would not come.
tflutre
Updated on February 22, 2021Comments
-
tflutre over 3 years
I get this error when downloading the Rcpp package:
> 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. What is strange is that I have rights to write in /home/me/src/Rlibs/. So my questions are:
- why does R want to have writing rights in /home while it only needs writing rights in /home/me/?
- 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
-
rjkunde over 6 yearsThis resolved the issue for me too, but I'm with @Garini, what is causing the file lock?
-
Adam Lee Perelman almost 6 yearsdeleting the file also helps
-
Ale over 5 years@rjkunde, I'm also trying to understand this issue. I see the folder 00LOCK is sometimes created when I already have the package (or a dependency) installed and there is a problem (not an error) in
install.packages()
. -
Ale over 5 yearsSometimes
unlink
does not remove the folder ad it is necessary to restart the R session. -
jimmyb over 5 yearsIn my experience, the shared file system NFS was mostly to blame. Someone with much more knowledge of the package management file-handling will hopefully speak up and correct me, but I assumed it was related to multiple distributed R processes spread over SGE cluster trying to interact with the package index files in LIB_PATH and the latency of cleaning up lock file on NFS file system.
-
Ale over 5 yearsThanks for the insight! Since my problem was that I was unable to remove the 00LOCK folder within the same R session because of a NFS file that cannot be removed, when installing a package I go through every package that will be imported (and the package itself), detach it, remove it, install it again, and attach it again. In this way it seems so far that no folder 00LOCK remains after all packages are installed. This without using
INSTALL_opts = c('--no-lock')
. -
Thorgas almost 5 yearsFixed the problem for me.
-
Mohammed over 4 yearsRemoving the entire directory recursively worked for me
-
carbocation over 4 yearsInteresting, I'm hitting this issue on OS X without any NFS. But, your solution worked.
-
Alperen Taciroglu almost 4 yearsThis solution helped me through many 00Lock package installation issues. Thanks for posting this!
-
Timothy M Pollington about 3 yearsNote that on the command line
R CMD INSTALL --no-lock <pkg>
may error if you are installing over a previous installation, giving the ERROR: cannot remove earlier installation, is it in use? message followed by an autoremoval of the old installation. So just runR CMD INSTALL --no-lock <pkg>
again and that should complete the installation. -
Timothy M Pollington about 3 yearsAlternatively this can also be applied in the RStudio GUI using
Build > Configure Build Tools > Build Tools left-hand tab > Install and Restart --- R CMD INSTALL additional options:
=--no-lock
This means you can then just chooseBuild > Install and Restart
, (though twice! for the same reason as my comment above for the command line. -
MGLondon about 3 yearsThis is what actually worked for me. None of the other solutions worked.