Search code examples
rlibraries

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


I realize that there are many similar topics such a 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. Howver, 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:

enter image description here

and for regular users:

enter image description here

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

enter image description here

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

enter image description here

I am running Windows 10 Home 10.0.19041


Solution

  • After way too many hours of frustration I found the culprit:

    enter image description here

    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). Now to figure out how to put R/RStudio on the exclusion list rather than shutting this option off completely.