-
Notifications
You must be signed in to change notification settings - Fork 18
Library is not writable [SOLUTION]
When trying to install a package you get the an error similar to this:
Warning in install.packages :
'lib = "<some library path>"' is not writable
Warning in install.packages :
Cannot create dir '<path>\?????', reason 'Invalid argument'
Error in install.packages : unable to create '<path>\?????'
Seems like you don't have writing permissions to the default folder, and R
is not able to create a new folder - possibly due to the default path having non ASCII letters? (This happens to my students with Hebrew paths.)
(These have only been tested on Windows...)
This solution is based on this guide.
- Close all windows of R or Rstudio.
- Open Start and search for
RStudio
. - Right-click the top result, and select Open file location.
- Right-click the app shortcut and select Properties.
- Click on the Shortcut tab, then on the Advanced button.
- Check the Run as administrator option.
- Click the OK button, then the Apply button, and finally the OK button.
- Open RStudio and try to install packages again.
Done.
If this doesn't work, try the next solution.
This solution is based on this awesome guide.
- Create a folder
This is where packages will be installed, so make sure you put is somewhere where it won't accidentally get deleted.
It should also be comprised of only base English letters.
Suggestion: Folder R_PKGS
in C:
.
-
Open
R
/ Rstudio as admin
Make sure no other windows of R/Rstudio are open. -
Run in R console
file.edit(file.path(R.home(component = "home"), "library", "base", "R", "Rprofile"))
This should open a file names Rprofile
. Scroll to the bottom of it.
- Add the following code to the bottom
#### MSB ####
{
# WHERE TO SAVE?
pkg_install_dir <- "<REPLACE ME WITH THE NEW PATH>"
if (.libPaths()[1] != pkg_install_dir) {
# DOES THE FOLDER EXIST?
if (pid_not_exist <- !file.exists(pkg_install_dir))
warning(pkg_install_dir, " directory does not exist.")
# IS THE FOLDER WRITABLE
if (!pid_not_exist && (pid_not_write <- file.access(pkg_install_dir, mode = 2)))
warning("Cannot write to", pkg_install_dir, ". Are you admin?")
# change file order
if (!pid_not_exist && !pid_not_write) {
.libPaths(unique(c(pkg_install_dir, .libPaths())))
cat("NOTE: Added ", pkg_install_dir, " to .libPaths(), as your default pkg installation folder.\n")
cat("NOTE: This may not work when updating or fresh-installing R.\n\n")
}
}
}
#### \MSB ####
And replace <REPLACE ME WITH THE NEW PATH>
with the full path to the new folder.
Note: that if your pack has any backslashes ("\", not "/"), they must be doubled. So C:\R_PKGS
must be C:\\R_PKGS
.
-
Save (
ctrl + S
) and closeR
/ Rstudio. -
Open
R
/ Rstudio
You should see in the console a message telling you that you path has been added as the default installation path.
- Install a package
It should work 🤷♂️