2

I have R 4.1.2 with RStudio 2021.09.2 on Windows 10 Enterprise on a University network. When I installed Rtools 4.0, I followed forum advice for putting Rtools on the path, including the following console commands:

write('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', file = "~/.Renviron", append = TRUE)
Sys.setenv(PATH = paste("C:/Rtools/bin", Sys.getenv("PATH"), sep=";"))
Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")

This has overwritten "PATH" and now R is unable to open system libraries. When I start RStudio I now get this error message:

During startup - Warning message:
package ‘stats’ in options("defaultPackages") was not found 
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Program Files/R/R-4.1.2/library/stats/libs/x64/stats.dll':
  LoadLibrary failure:  The specified module could not be found.

Instead of appending the Rtools PATH, I seem to have deleted the previous value of PATH:

> Sys.getenv("PATH")
[1] "C:\\rtools40\\usr\\bin;"

I tried accessing .Renviron using usethis::edit_r_environ but this package no longer works now.

> usethis::edit_r_environ()
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Program Files/R/R-4.1.2/library/stats/libs/x64/stats.dll':
  LoadLibrary failure:  The specified module could not be found.

I would like to recover the previous value of PATH but I don't know how to find out what this was. How can I do this? I'd rather not delete and reinstall R unless absolutely necessary, as this is on a University system and I don't have admin rights.

Edit: Now fixed! Using R itself (instead of RStudio) I was able to access .Renviron using usethis::edit_r_environ() and delete the entry PATH=...

Then after restarting R, PATH reverted to its original value.

batcatcher
  • 33
  • 3
  • 2
    Restart the computer. The PATH variable values are not preserved across restarts. If you remove the code from the `~/.Renviron` then your path should be restored on startup. – MrFlick Jan 23 '23 at 14:33
  • Consider adding R to PATH via the Windows GUI where you search "environment variables" in start menu and can either adjust user account level or system level (if you have admin rights). Find *Path* at the top and edit to add new R bin folder. – Parfait Jan 23 '23 at 15:12
  • @MrFlick once I was able to remove the code from `~/.Renviron` and restart R the problem was fixed. Accessing `~/.Renviron` was difficult though, till I tried using R instead of RStudio. – batcatcher Jan 23 '23 at 16:38
  • `~/.Renviron` should just be a text file in your home directory. You don't need to use R to delete it or edit it. But i'm glad you got it working. – MrFlick Jan 23 '23 at 18:01

0 Answers0