R Install - Packages Returns Failed To Create Lock Directory - Stack Overflow

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

R install.packages returns "failed to create lock directory... https://stackoverflow.com/questions/14382209/r-install...

R install.packages returns "failed to create lock directory"


Asked 10 years, 6 months ago Modified 2 years, 4 months ago Viewed 119k times
Part of R Language Collective

Join Stack Overflow to find the best answer to your technical question, help others answer theirs.

Sign up with email Sign up with Google Sign up with GitHub Sign up with Facebook

1 of 5 7/21/23, 16:19
R install.packages returns "failed to create lock directory... https://stackoverflow.com/questions/14382209/r-install...

I get this error when downloading the Rcpp package:

103 > 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:

1. why does R want to have writing rights in /home while it only needs writing rights in
/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

r package rcpp

Share Follow edited Feb 4, 2020 at 16:46 asked Jan 17, 2013 at 15:16
marzecovaa tflutre
9 3 3,344 9 39 53

5 Answers Sorted by: Highest score (default)


Join Stack Overflow to find the best answer to your technical question, help others answer theirs.

Sign up with email Sign up with Google Sign up with GitHub Sign up with Facebook

2 of 5 7/21/23, 16:19
R install.packages returns "failed to create lock directory... https://stackoverflow.com/questions/14382209/r-install...

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.:
190
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')

Share Follow edited Jan 23, 2020 at 11:49 answered Jan 17, 2013 at 22:09
Konrad Rudolph jimmyb
528k 131 935 1213 4,217 2 23 26

5 This resolved the issue for me too, but I'm with @Garini, what is causing the file lock? – rjkunde Dec
19, 2017 at 16:33

@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 Oct 17, 2018 at 8:37

1 In 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.
– jimmyb Oct 18, 2018 at 8:31

Thanks 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') . – Ale Oct 18, 2018 at 10:59

Interesting, I'm hitting this issue on OS X without any NFS. But, your solution worked. – carbocation
Jan 23, 2020 at 15:46

Join Stack Overflow to find the best answer to your technical question, help others answer theirs.

Sign up with email Sign up with Google Sign up with GitHub Sign up with Facebook

3 of 5 7/21/23, 16:19
R install.packages returns "failed to create lock directory... https://stackoverflow.com/questions/14382209/r-install...

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:
43
unlink("/home/me/src/Rlibs/00LOCK-Rcpp", recursive = TRUE)

Hope this helps!

Share Follow edited May 6, 2018 at 10:47 answered Feb 25, 2018 at 13:43
Sina
702 7 9

11 deleting the file also helps – Adam Lee Perelman Aug 5, 2018 at 9:06

3 Sometimes unlink does not remove the folder ad it is necessary to restart the R session. – Ale Oct
17, 2018 at 8:40

1 Fixed the problem for me. – NFoerster Aug 24, 2019 at 10:31

Removing the entire directory recursively worked for me – Mohammed Oct 11, 2019 at 14:57

The easiest way to avoid this issue is before installing any package run the line below

18 options("install.lock"=FALSE)

Then try the install.packages("name_of_package") to install the package. The 00LOCK error
would not come.

Share Follow answered Feb 22, 2021 at 7:37


Ransingh Satyajit Ray
351 2 8

5 This is what actually worked for me. None of the other solutions worked. – MGLondon Jun 23, 2021 at
16:58

2 God bless you man! – Mehrdad Zandigohar Jul 21, 2022 at 6:57

Join Stack Overflow to find the best answer to your technical question, help others answer theirs.

Sign up with email Sign up with Google Sign up with GitHub Sign up with Facebook

4 of 5 7/21/23, 16:19
R install.packages returns "failed to create lock directory... https://stackoverflow.com/questions/14382209/r-install...

This can happen when you are upgrading to a major version of the R as well. Some major
upgrades require you to rebuild your packages, e.g., R 4.0. In my case, I had installed R
0 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.

To resolve it, you need to make sure that Homebrew removes leftovers of your older R
installation. In default setting, you can find them here, /usr/local/lib/R . I had instances of
3.5 , and 3.6 besides the rest of R's internal. You can remove everything there, and install R
again, and everything should work fine. Or just remove the older version of R, and empty the
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:

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

Share Follow answered May 6, 2020 at 12:06


Amir
1,087 1 9 25

I encountered a similar problem running windows 7:

-1 Error in install.packages : ERROR: failed to lock directory ‘D:\Program Files\R


\R-3.6.2\library’ for modifying.

I solved this problem with below command in the R-console:

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

Hope this help windows users...

Share Follow edited Dec 18, 2019 at 15:57 answered Dec 18, 2019 at 15:39
ZF007 PatrickC
3,698 8 29 48 9 2

Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this
Join Stack The
question. Overflow to find
reputation the best
requirement answer
helps to this
protect your technical
question fromquestion,
spam and help othersactivity.
non-answer answer theirs.

Sign up with email Sign up with Google Sign up with GitHub Sign up with Facebook

5 of 5 7/21/23, 16:19

You might also like