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

3
  • 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, 2019 at 9:24
  • stackoverflow.com/questions/15217758/… seems to imply to the contrary. Many of the steps above are from this thread. thanks Apr 16, 2019 at 4:24
  • 1
    That question is about removing a user-specific directory, not the base R install directory.
    – Hong Ooi
    Apr 16, 2019 at 4:33

2 Answers 2

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."

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.