Skip to content

Rgui, Startup, HOME, R_USER, ...

5 messages · Henrik Bengtsson, Duncan Murdoch, Gabor Grothendieck

#
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.  Excuse me for my lack of
understanding WinXP, but why is this?  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 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
R_USER
"C:\\Documents and Settings\\hb\\My Documents"
M:\>set HOME=%HOMEDRIVE%\%HOMEPATH%
M:\>Rterm --quiet
R_USER
"C:\\\\Documents and Settings\\hb"

M:\>set HOME=%HOMEDRIVE%\%HOMEPATH%\foo
M:\>Rterm --quiet
R_USER
"C:\\\\Documents and Settings\\hb\\foo"
Documents/ for Rgui to find it by default.  Is this behavior
documented somewhere and why this specific directory?  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).

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

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

Best,

/Henrik
#
Just a few comments:

- although one can use environment variables in Windows applications
(I am referring to applications generally and not just R) its not
the preferred way of doing things.  Its ok to support environment
variables but they should not be relied on as the preferred way
to set configurations though they could be an alternate way.

- HOME is really bad since it can conflict with other applications,
usually ones that have been ported from UNIX

- to find out how startup works I think you will likely have to review the
startup source of code of R.  I once tried to add some lookup of these to
batchfiles (but I ultimately decided to simplify it to the point
where none of them were required) and found that reviewing the R
souce was the quickest way to be sure. That was
a whlie ago though.
On 5/4/06, Henrik Bengtsson (max 7Mb) <hb at stat.berkeley.edu> wrote:
#
On 5/4/2006 5:49 PM, Henrik Bengtsson (max 7Mb) wrote:
On my system, doing that gives a different directory:  the desktop.
Presumably Windows Explorer is doing something special with %HOME%. 
It's not simply an environment lookup.

 > What sysenv variables are
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).
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!
It's in an appendix of the R Intro manual, "Invoking R under Windows".

 > For parallelism
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 ~.
You could, but you're not supposed to be writing there.
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
#
(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:
On my system, doing that gives a different directory:  the desktop.
Presumably Windows Explorer is doing something special with %HOME%. 
It's not simply an environment lookup.

 > What sysenv variables are
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).
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!
It's in an appendix of the R Intro manual, "Invoking R under Windows".

 > For parallelism
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 ~.
You could, but you're not supposed to be writing there.
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
#
On 5/4/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:

            
I have never tried it but I think it could be done using regedit by
by setting the appropriate registry key:
http://vlaurie.com/computers2/Articles/environment.htm

It can also be done via vbscript, javascript or any programming language
that can access COM objects, such as R with RDCOMClient or rcom,
using the wscript.shell object:
http://hacks.oreilly.com/pub/h/1107