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

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon Nov 22 20:13:12 CET 2021


On 22/11/2021 1:06 p.m., Jiefei Wang wrote:
> Thanks for all your help!! It actually has nothing to do with the
> environment variables. The issue is caused by the backup feature in
> Onedrive as Bill suggested. I do not know what magic trick Onedrive
> uses here but it misadvices R to use its directory, not my local
> Document directory. The answer might be from Windows FAQ question 2.14
> like Duncan posted
> 
> After those two user-controllable settings, R tries to find
> system-defined home directories. It first tries to use the Windows
> "personal" directory
> 
> This is confusing. First, this FAQ is not about how "R_USER" is
> defined.

R_USER is an optional environment variable that *you* can set.  If you 
do, it's taken to be the home directory.  If it is not set, the rest of 
the FAQ 2.14 entry is tried.

So if R is coming up with the wrong home directory, the solution is to 
set R_USER to be the directory you want to use.  You have to do this 
before starting R, you can't use Sys.setenv():  it's too late by then.

The easiest way to set an environment variable for R to use is to set it 
in the R_HOME/etc/Renviron.site file.  You can alternatively set it in 
the .Renviron file, but it may be a little mysterious in Windows where 
you should save that.

You can also set environment variables using Windows control panel 
settings, but I don't think I ever learned the details of this for 
Windows 10.  That can be global for all programs for one user, or global 
for all users, depending on how you set it.

Duncan Murdoch

  Instead, it talks about how we find the home directory from
> "R_USER". Second, it still did not answer what is "the Windows
> personal directory". I think this is where the issue is. My Document
> still has the path "C:\Users\wangj\Documents", but there is a backup
> path in "C:\Users\wangj\OneDrive\Documents". Unfortunately, R believes
> the latter one is the "personal directory". I hope this can be
> clarified a little bit to avoid confusion.
> 
> Best,
> Jiefei
> 
> On Mon, Nov 22, 2021 at 12:32 PM Bill Dunlap <williamwdunlap using gmail.com> wrote:
>>
>> Is your C:\Users\yourname\Documents linked to OneDrive (either by your choice or by some administrator setting a group policy)?  If so, ou could unlink it using OneDrive's settings dialog.   Or you could set R_USER to avoid using ...\Documents.
>>
>> -Bill
>>
>> On Mon, Nov 22, 2021 at 8:47 AM Jiefei Wang <szwjf08 using gmail.com> 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...
>>>
>>> Best,
>>> Jiefei
>>>
>>> ______________________________________________
>>> R-devel using r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list