0

Win 7 64 bit machine R version 3.5.3 (2019-03-11)

Question: How do I set my library paths to have only one directory, namely: "C:/Users/Username/Documents/R/win-library/3.5" ?

I added .libPaths("C:/Users/Username/Documents/R/win-library/3.5") to RProfile.site

Set R_LIBS_USER and R_LIBS to: C:\Users\Username\Documents\R\win-library\3.5

R_LIBS_SITE:

[1] "C:\\Users\\Username\\Documents\\R\\win-library\\3.5"

yet when I start RStudio and input:

> .libPaths()
[1] "C:/Users/Username/Documents/R/win-library/3.5" "C:/Program Files/R/R-3.5.3/library"

I still end up with two library paths (as above).

Furthermore, in RStudio I am not able to set lib-paths to just "C:/Users/Username/Documents/R/win-library/3.5" with these steps:

> .libPaths("C:/Users/Username/Documents/R/win-library/3.5")
> .libPaths()
[1] "C:/Users/Username/Documents/R/win-library/3.5" "C:/Program Files/R/R-3.5.3/library" 
> .libPaths("C:/Program Files/R/R-3.5.3/library")
> .libPaths()
[1] "C:/Program Files/R/R-3.5.3/library"
> .libPaths("C:/Users/Username/Documents/R/win-library/3.5")
> .libPaths()
[1] "C:/Users/Username/Documents/R/win-library/3.5" "C:/Program Files/R/R-3.5.3/library"

An attempt to set lib-paths by editing .Renviron with:

> usethis::edit_r_environ()

Added .libPaths("C:\Users\Username\Documents\R\win-library\3.5") to and saved .Renviron file. This resulted in an R Message upon restarting R:

File C:/Users/Username/Documents/.Renviron contains invalid line(s) .libPaths("C:\Users\Username\Documents\R\win-library\3.5")

Thank you

analytics-josh
  • 135
  • 2
  • 12
  • 2
    You can't, and you don't want to, remove the base library location. That's where R's own packages live, and without them you can't use R. – Hong Ooi Apr 15 '19 at 09:24
  • https://stackoverflow.com/questions/15217758/remove-a-library-from-libpaths-permanently-without-rprofile-site seems to imply to the contrary. Many of the steps above are from this thread. thanks – analytics-josh Apr 16 '19 at 04:24
  • 1
    That question is about removing a _user-specific_ directory, not the base R install directory. – Hong Ooi Apr 16 '19 at 04:33

2 Answers2

0

Hong Ooi's answer: "You can't, and you don't want to, remove the base library location. That's where R's own packages live, and without them you can't use R."

analytics-josh
  • 135
  • 2
  • 12
0

Instead of using .Renviron, can you try it with Rprofile?

in the RStudio console window:

usethis::edit_r_profile()

This will open the .Rprofile file, located in the default R_USER folder

In the RStudio code window, write (or add) the following, then save:

.libPaths(c("C:/R/Library", .libPaths()[-1]))

This code replace the first element of the libPaths list with the "C:/R/Library" value. Restart RStudio, and you're done. You can check it by typing .libPaths() in the console window.

As for the second element of the list ("~/R/R-4.1.2/library" or the like), you cannot remove it as it contains R own packages.

Philippe Grondier
  • 10,900
  • 3
  • 33
  • 72