Library is not writable

RUbuntu

R Problem Overview


I have this issue during package installation in R version 3.0.2 (2013-09-25) on an Ubuntu machine:

install.packages("randomForest")
Installing package into ‘/usr/local/lib/R/site-library’
(aslibis unspecified)
Warning in install.packages :
  'lib = "/usr/local/lib/R/site-library"' is not writable

How to resolve it?

R Solutions


Solution 1 - R

For R version 3.2.2 (2015-08-14) this problem should be dealt with since R suggests within the installation process a different path to store your R libraries. The installation looks like this: (Here 'random' is used as an example package)

install.packages('random')

Installing package into ‘/usr/local/lib/R/site-library’
(aslibis unspecified)
Warning in install.packages("random") :
'lib = "/usr/local/lib/R/site-library"' is not writable

Would you like to use a personal library instead?  (y/n) y

Would you like to create a personal library
~/R/pc-linux-gnu-library/3.2
to install packages into?  (y/n) y

So during the installation answering both questions with 'y' should install the package correctly.

Update 18/01/19

In case you don't want to store your R packages in an additional file:

As Antoine-Sac and Robert TheSim point out you can add yourself to the staff group in order to be able to write to 'site-library'. (Click on the names to see their important additions)

Before this update I mentioned in this comment the option of changing the permission of the folder 'site-library' using 'chmod o+w' in order to be able to write to it. Assuming security issues but unable to tell at the time I warned about it but have primarily been waiting for somone to clear this up. Antoine-Sac and Robert TheSim have done so in the meantime. Thanks!

Solution 2 - R

If you are on Windows, you can run R (or RStudio) as an administrator.

Close your R, then go to the R or RStudio icon, right-click and "open as administrator". It works perfectly, all error messages while installing packages are gone forever.

Solution 3 - R

add yourself to the group called 'staff'

sudo usermod -a -G staff your_user_name

replace your_user_name with your login username, then logoff and relogin.

DO NOT use chmod 777 which is a breach of security and btw. a complete non-sense!!!

Solution 4 - R

For someone who tried to use install.packages() with multiple packages like this:

install.packages("vcd","vcdExtra","plyr")

and got similar warning:

Warning in install.packages :
  'lib = "vcdExtra"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) cancel
Error in install.packages : unable to install packages

You should put the package names in a vector:

install.packages(c("vcd","vcdExtra","plyr"))

as the second parameter in install.packages() is lib.

Solution 5 - R

The problem is that the default install location is a place where you do not have write permissions.

The solution is to use an install location where you do have write permissions.

Specifically, I'd suggest using the following commands to create a personal library folder in a place that doesn't require special permissions and that will automatically be detected the next time you startup R:

dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)  # create personal library
.libPaths(Sys.getenv("R_LIBS_USER"))  # add to the path

install.packages("randomForest")  # install like always
library(randomForest)  # use library like always

The call to dir.create follows the suggestion in this faq to create a folder named according to Sys.getenv("R_LIBS_USER"). This is a good choice since it will be found on the next startup of R so you will be able to use install.packages and library without specifying special locations. The .libPaths function call lets us avoid restarting R by immediately adding the new folder to the library path. The first two lines are only needed if you do not yet have a personal library created, but there is no harm in running them repeatedly. After that, installing packages and using libraries can be done as usual.

Solution 6 - R

It means exactly what it says. You don't have write permission in that folder. Either you need to change the permissions for that folder, or change the R library location.

Solution 7 - R

If you are using OS windows 10 then maybe Ransomware protection is on. You need to disable that.

I was facing the same problem. I had the access to write. but suddenly it stopped. I couldn't install the packages. Disabling Ransomware protection worked for me.

Solution 8 - R

The "XX" is not writable error can also mean that the library path you're providing does not exist.

Solution 9 - R

If you are using R with RStudio, rather than starting RStudio with tray icon, start Rstudio or R with command line using sudo rstudio or sudo R.

It will solve your problem for sure, it works for me. It requires sudo privilege to write something in installation directory.

Solution 10 - R

You can change permission to 'site-library' and all included directories.

sudo chmod 777 -R /usr/local/lib/R/site-library

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPriya View Question on Stackoverflow
Solution 1 - Rmanuel_vaView Answer on Stackoverflow
Solution 2 - RSeyiView Answer on Stackoverflow
Solution 3 - RRobert TheSimView Answer on Stackoverflow
Solution 4 - RBanAnanasView Answer on Stackoverflow
Solution 5 - RteichertView Answer on Stackoverflow
Solution 6 - RshadowtalkerView Answer on Stackoverflow
Solution 7 - RMohammed SouravView Answer on Stackoverflow
Solution 8 - RLjupcho NaumovView Answer on Stackoverflow
Solution 9 - Ruser3218971View Answer on Stackoverflow
Solution 10 - RIgor MisechkoView Answer on Stackoverflow