0

Trying to update.packages() in emacs ess and some packages will not update. I think this is a library/permission issue. I uninstalled R from my machine and deleted my libraries. I then installed R 4.1.2 and went to install packages and update.packages. I got this error code:

  'lib = "C:/Program Files/R/R-4.1.2/library"' is not writable...
Would you like to use a personal library instead? (yes/No/cancel) 

I said yes and created a personal library

C:\Users\user\R\win-library\4.3

But I still get the same issue

 update.packages()
Warning: package 'class' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated
Warning: package 'foreign' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated
Warning: package 'MASS' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated
Warning: package 'Matrix' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated
Warning: package 'nlme' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated
Warning: package 'nnet' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated
Warning: package 'rpart' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated
Warning: package 'spatial' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated

Why is it still trying to write to the wrong library?

Drew
  • 29,895
  • 7
  • 74
  • 104
Jacob
  • 173
  • 8
  • 1
    Are you sure it created `...\4.3`? That should be `...\4.1` for R-4.1.2, as the directory structure is required for how R looks for libraries specific to the major/minor version of R. See [`?.libPaths`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html) for more about this. (If you created the directory manually, then ... still, read the docs :-) – r2evans Feb 01 '22 at 21:30
  • yes that was the default directory suggested by R on the installation.... – Jacob Feb 01 '22 at 21:36
  • I understand what you're saying, but that goes against everything in the R documentation. Perhaps there is something external to R changing envvars? Either way, try renaming `4.3` to `4.1` then restart R (and likely RStudio as well). – r2evans Feb 01 '22 at 21:48
  • I found that ```R_LIBS_USER``` was set to ```...\4.3``` I changed it to ```...\4.1``` and then uninstalled R, removed all libraries and the ```...\4.3``` directory and reinstalled R. ```...\4.1``` is now the default personal library, but I get the same error on the same packages as above. even after telling R to install in my personal library. – Jacob Feb 01 '22 at 21:55
  • There should not be the need to uninstall/reinstall R, but it also shouldn't hurt (it's just busy work). You may want/need to look at `~/.Rprofile`, `~/.Renviron`, and any `.Rproj` files in specific project directories, in case they either call `.libPaths(...)` or overwrite `R_LIBS_USER` or other related envvars. – r2evans Feb 01 '22 at 21:56
  • 1
    Is there any possibility that you have two versions of the packages that are in the list? You can check: `pack = installed.packages()`; `pack = data.frame(pack[, c('Package', "LibPath")])`; `pack[pack$Package == "MASS" | pack$Package == "foreign" | pack$Package == "class", ]; What happens if you use `update.packages()` opening R from any shell/terminal? – Jose Feb 01 '22 at 22:00
  • Jose, good call... ``` class class C:/Users/user/R/win-library/4.1 foreign foreign C:/Users/user/R/win-library/4.1 MASS MASS C:/Users/user/R/win-library/4.1 class.1 class C:/Program Files/R/R-4.1.2/library foreign.1 foreign C:/Program Files/R/R-4.1.2/library MASS.1 MASS C:/Program Files/R/R-4.1.2/library ``` so how do i remove the extra copies in the program files directory? – Jacob Feb 01 '22 at 22:02
  • @r2evans, I do not see anything in those files that overwrite R_LIBS_USER... – Jacob Feb 01 '22 at 22:22
  • @Jacob: you can use `remove.packages()`; Try removing from the personal library – Jose Feb 02 '22 at 00:10
  • @Jose when I remove packages and run the code you suggest, I only see one copy of the package in the program file directory library. when I then ```update.packages()``` I am back in the same loop of R asking me if I want to install in the personal library and then the installation fails. – Jacob Feb 02 '22 at 06:57
  • Possibly this is related to EMACS or my .emacs file ```file.edit("~/.Rprofile") Warning message: In file.edit("~/.Rprofile") : '"emacsclient"' not found``` – Jacob Feb 02 '22 at 10:01
  • resolved! I followed a similar case here https://stackoverflow.com/questions/20587440/some-r-packages-do-not-update-with-update-packages basically, I removed the duplicate packages from the personal directory, quit R, and then started R from R.exe as admin (instead of running from within EMACS) and was able to update the packages. Is this expected behavior or should I still tweak something so that this does not happen? – Jacob Feb 02 '22 at 10:55
  • Great! Thank you for sharing your solution! @Jacob – Jose Feb 02 '22 at 12:53

0 Answers0