[Rd] How is the environment variable "R_USER" defined?

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon Nov 22 18:19:19 CET 2021

On 22/11/2021 11:46 a.m., Jiefei Wang wrote:
> Hi, I have a new win system and try to install R as usual. Somehow,
> the environment variable "R_LIBS_USER" is incorrectly pointed to a
> Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
> problem then becomes why "R_USER" is the path to the Onedrive. I did
> an exhausting search in the R directory and the only related message I
> can find is from EnvVar.html, which states
> R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
> the same value if not already set.)
> I guess that's another way to say "no document is available yet". I
> also took a look at my system environment variables but there are only
> two variables related to Onedrive, they are
> OneDrive=C:\Users\wangj\OneDrive
> OneDriveConsumer=C:\Users\wangj\OneDrive
> so everything looks pretty normal, I know I can correct this issue by
> manually adding Renviron but I just wonder where this default behavior
> comes from...

I think you want to look at the Windows FAQ. From question 2.14:

The home directory is set as follows: If environment variable R_USER is 
set, its value is used. Otherwise if environment variable HOME is set, 
its value is used. After those two user-controllable settings, R tries 
to find system-defined home directories. It first tries to use the 
Windows "personal" directory (typically C:\Users\username\Documents). If 
that fails, if both environment variables HOMEDRIVE and HOMEPATH are set 
(and they normally are), the value is ${HOMEDRIVE}${HOMEPATH}. If all of 
these fail, the current working directory is used.

Duncan Murdoch

More information about the R-devel mailing list