[Rd] Rgui, Startup, HOME, R_USER, ...

Duncan Murdoch murdoch at stats.uwo.ca
Fri May 5 00:56:46 CEST 2006


(Not sure if the previous message went out; sorry if this is a dupe. 
The only change is to fix the subject.)

On 5/4/2006 5:49 PM, Henrik Bengtsson (max 7Mb) wrote:
> Hi,
> 
> Main objective: Let Rgui find my ~/.Rprofile and ~/.Renviron files,
> where ~ is equal to getwd("~").
> 
> I have few comments/questions:
> 
> (A) On my WinXP Pro installation, the system environment variable
> 'HOME' is not availble to R, e.g. Sys.getenv("HOME") is empty.  I
> believe this is default case (correct me if I'm wrong).  However, if I
> set the "Start in:" to %HOME% in the Properties for the Rgui.exe file,
> the working directory is indeed set to getwd("~"), so 'HOME' is
> available for the startup of R. 

On my system, doing that gives a different directory:  the desktop.

> Excuse me for my lack of
> understanding WinXP, but why is this?  

Presumably Windows Explorer is doing something special with %HOME%. 
It's not simply an environment lookup.

 > What sysenv variables are
> available to the R process?  PS. I know I can add HOME=<path> in the
> Rgui.exe properties, however I'm interested in the default lookup
> path. DS.
> 
> (B) With the default "Start in:" value of "C:\Program
> Files\R\R-2.3.0pat", the ~/My Documents/.Rprofile is called.  I tried
> to understand why exactly this path.  Reading the R FAQ for Windows,
> it says that 'R_USER' is used as the default value for the home
> directory.  Where/when is this set, and how?  I don't set it myself. 

It's set by R during the startup if you didn't set it before that.  In 
XP, some of the environment variables given to new processes started 
from Explorer are found in

Control Panel|System|Advanced|Environment Variables

Other ones are also set, e.g. HOMEDRIVE and HOMEPATH (which as we found 
last year, are not set consistently).


> It looks like it is set equal to 'HOME' and if that is not set, the to
> the default %HOMEDRIVE%\%HOMEPATH%\My Documents\, e.g.
> 
> M:\>set HOME=
> M:\>Rterm --quiet
>> Sys.getenv("R_USER")
>                                         R_USER
> "C:\\Documents and Settings\\hb\\My Documents"

What you see in a command shell may be different, because variables can 
be set or cleared when the shell starts up.  Whatever happens there is 
local to the shell, so programs started directly from Explorer won't see 
the changes.

I imagine there's a way to change the global values from the shell, but 
I don't know it.  Gabor probably does!

> M:\>set HOME=%HOMEDRIVE%\%HOMEPATH%
> M:\>Rterm --quiet
>> Sys.getenv("R_USER")
>                             R_USER
> "C:\\\\Documents and Settings\\hb"
> 
> M:\>set HOME=%HOMEDRIVE%\%HOMEPATH%\foo
> M:\>Rterm --quiet
>> Sys.getenv("R_USER")
>                                  R_USER
> "C:\\\\Documents and Settings\\hb\\foo"
> 
>>From the above I found out that I should put .Rprofile etc in ~/My
> Documents/ for Rgui to find it by default.  Is this behavior
> documented somewhere and why this specific directory?  

It's in an appendix of the R Intro manual, "Invoking R under Windows".

 > For parallelism
> to Unix etc, it would be more natural to have ~/.Rprofile search for
> by default, but that is not the case (unless I set HOME).

The ~ path is not a Windows concept, it's faked by R. Windows has a much 
more complicated idea of what a user environment is like than Unix does, 
with a few dozen special directories defined (google for the 
ShGetSpecialFolderLocation docs for the list).  The normal place to put 
things that the user will edit corresponds to ~/My Documents. 
~/Application Data is normally the place to store user-specific config 
files that the user won't edit directly.  Nobody but Windows is supposed 
to write to the directory R calls ~.

> (C) Is it possible to set HOME globally to %HOMEDRIVE%\%HOMEPATH% once
> and for all without editing the Rgui.exe properties?

You could, but you're not supposed to be writing there.

> (D) Depending a little bit how and when R_USER is set, could I suggest
> the the default "Start in:" path for Rgui.exe is changed from the
> installation directory to %HOME% instead?  This is more user friendly,
> especially to beginners, I think.

It might make sense (from a Windows point of view) to change it to the 
My Documents folder.  I'm not sure what the official definition of 
%HOME% is.

Duncan Murdoch



More information about the R-devel mailing list