Why .libPaths() does show different values in RStudio and R in the same box and user?

Hi!

I'm struggling to understand how my RStudio/R environment deals with libraries. I'm working with a Windows 10 installation with RStudio and R fully updated. Until today, .libPaths() shows the same output, both when submitted within RStudio IDE or when in an R Gui window. After changing locale in Windows to experimental utf-8, here what I get:

  • RStudio:

.libPaths()
[1] "C:/Program Files/R/R-3.6.1/library"

  • RGui (64-bit)

.libPaths()
[1] "C:/Users/Ricardo Rodríguez/Documents/R/win-library/3.6" "C:/Program Files/R/R-3.6.1/library"

Please, could you help me to understand why? Thanks!

Rstudio is simply loading a different value for the R_LIBS_SITE environmental variable, by defaul includes the user level library ("C:/Users/Ricardo Rodríguez/Documents/R/win-library/3.6"), and the system level library ("C:/Program Files/R/R-3.6.1/library"), in that order. You can overwrite this by setting a custom value in your Renviron.site file.

1 Like

Thanks! I think I can understand what you explained, but I'm not able to find why my RStudio installation doesn't include my user-level library any longer! Here what I did:

  1. Change Windows 10 locale to utf-8
  2. Restart the system
  3. Open again RStudio

Before setting locale to utf-8, .libPaths() shows both, user-level and system libraries. After the restart, only the system is available. I don't miss the user-level library at all: it includes accentuated letters that are causing a lot of problems when I tried to compile packages, but I would like to understand what is happening here. To the best of my current understanding, I've not Renviron.site file here.
Thanks!

Odds are that, by changing the locale, RStudio is no longer able to correctly decode some paths in your environment variables, and this leads to eventually failing to find and set the correct library paths. This may also be occurring because your user account name contains an accented character, which will be encoded different in different encodings.

2 Likes

Thanks. This accented character in my path is causing more than one headache.

Still, I would like to understand what I'm getting here. Please, could you, or anybody else, tell me if the next sentences are correct or not? Thanks in advance?

  1. In Windows 10, if I've no R startup files (neither .Rprofile nor Rprofile.site), the library path is set by the settings of the R version behind RStudio.
  2. In the same box, .libPaths() should give me the same results both in R 3.6.1 and RStudio.
  3. If the results are different, I should suspect that RStudio is not able to read the same settings R correctly reads.

Thus, here my question, where are R reading those settings?

Thank you so much for your help!

This normally comes from the R_LIBS_USER environment variable, which (if unset) will be set by R when the R session is initialized. The likely cause of the issue you're seeing is that RStudio is mis-encoding the contents of that environment variable when attempting to read it, due to the use of the experimental UTF-8 locale.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.