'lib = "C:/Users/xxx/Documents/R/win-library/4.0"' is not writable

I realize that there are many similar topics such as mine, but none of the appear to resolve my issues. From one day to the next I am now unable to install any packages. I always get the following error:

> install.packages("gapminder")
Installing package into ‘C:/Users/mario/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "C:/Users/mario/Documents/R/win-library/4.0"' is not writable

If I then chose the option to 'use a personal library instead' I get:

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/gapminder_0.3.0.zip'
Content type 'application/zip' length 2031853 bytes (1.9 MB)
downloaded 1.9 MB

Warning in install.packages :
  cannot create dir 'C:\Users\mario\Documents\R\win-library\4.0\filecb869a32b3e', reason 'No such file or directory'
Error in install.packages : unable to create temporary directory ‘C:\Users\mario\Documents\R\win-library\4.0\filecb869a32b3e’

Googling on SO and other places suggests that this is a permission issue. However, I double checked and I am running RStudio under admin permission and I have double-checked that both RStudio and R 4.0 have full read/write privilege for admins:

and for regular users:

The library folder exists and is full of all the libraries that I always use:

And I believe this is independent of RStudio since going straight to R and trying to install from there leads to the same problems:

I am running Windows 10 Home 10.0.19041

I don't have a solution for your specific problem but I can suggest using the system level package library as a walk around.

You can change the default library folder by setting your R_LIBS_SITE environmental variable on a .Reviron or .Rprofile file

# In a .Renviron file you can set it by adding this line
R_LIBS_SITE="C:\\Program Files\\R\\R-4.0.3\\library"

For a more detailed explanation, you can read this blog post

1 Like

Thank you for your comment @andresrcs.

I am really interested in finding a solution to the problem so I have been doing a little more troubleshooting. For some reason it seems that R is simply unable (not allowed) to write to the majority of my directories (except for a scant few where it is set to execute).

I simply started setting my working directory to various spots and then tried to write a little CSV.

This works as expected:

dummy <- "test"
setwd("C:/Users/mario/OneDrive - Ribon Therapeutics/R projects")
head(dir())
#> [1] "__install files"        "_books and manuals"     "_cheat sheets"         
#> [4] "_scratch"               "_themes"                "20200507_EB_NAFLD-NASH"
write.csv(dummy, "___test.csv")
head(dir())
#> [1] "___test.csv"        "__install files"    "_books and manuals"
#> [4] "_cheat sheets"      "_scratch"           "_themes"

As does this:

dummy <- "test"
setwd("C:/Users/mario")
head(dir())
#> [1] "3D Objects"       "AppData"          "Application Data" "Contacts"        
#> [5] "Cookies"          "Desktop"
write.csv(dummy, "___test.csv")
head(dir())
#> [1] "___test.csv"      "3D Objects"       "AppData"          "Application Data"
#> [5] "Contacts"         "Cookies"

But this fails:

dummy <- "test"
setwd("C:/Users/mario/Documents")
head(dir())
#> [1] "___Zwift Backup" "Aquarium"        "auctions"        "Audiobooks"     
#> [5] "Bert Gift"       "Blog"
write.csv(dummy, "___test.csv")
#> Warning in file(file, ifelse(append, "a", "w")): cannot open file '___test.csv':
#> No such file or directory
#> Error in file(file, ifelse(append, "a", "w")): cannot open the connection
head(dir())
#> [1] "___Zwift Backup" "Aquarium"        "auctions"        "Audiobooks"     
#> [5] "Bert Gift"       "Blog"

As does this:

dummy <- "test"
setwd("C:/Users/mario/Documents/R/win-library/4.0")
head(dir())
#> [1] "abind"      "afex"       "askpass"    "assertthat" "backports" 
#> [6] "base64enc"
write.csv(dummy, "___test.csv")
#> Warning in file(file, ifelse(append, "a", "w")): cannot open file '___test.csv':
#> No such file or directory
#> Error in file(file, ifelse(append, "a", "w")): cannot open the connection
head(dir())
#> [1] "abind"      "afex"       "askpass"    "assertthat" "backports" 
#> [6] "base64enc"

So this suggests to me it has something to do with the oddity that is the documents folder in Windows. The bizarre thing is that this is where the R libraries have always been and I have not implemented any changes! Bizzarre.

Created on 2021-02-10 by the reprex package (v0.3.0)

After way too many hours of frustration I found the culprit: Turning off real-time protection on Windows Security fixes the issue:

> install.packages("gapminder")
Installing package into ‘C:/Users/mario/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/gapminder_0.3.0.zip'
Content type 'application/zip' length 2031853 bytes (1.9 MB)
downloaded 1.9 MB

package ‘gapminder’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\mario\AppData\Local\Temp\RtmpGi9Jo9\downloaded_packages

That explains why the problem appeared from one day to the next (Windows 10 update) and why it doesn't show on my work laptop (IT-managed updates).

It would be better to white list RStudio instead of disabling real-time protection, which could pose a big security risk for you.

Thank you for the warning, @andresrcs. I only turned it off completely for testing. Now it's back on and R/RStudio are whitelisted.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.