From hb at stat.berkeley.edu  Thu May  4 23:49:58 2006
From: hb at stat.berkeley.edu (Henrik Bengtsson (max 7Mb))
Date: Thu, 4 May 2006 14:49:58 -0700
Subject: [Rd] Rgui, Startup, HOME, R_USER, ...
Message-ID: <59d7961d0605041449q6a7086f0gd7c4d503527f6bd0@mail.gmail.com>

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
> Sys.getenv("R_USER")
                                        R_USER
"C:\\Documents and Settings\\hb\\My Documents"
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?  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



[Rd] Rgui, Startup, HOME, R_USER, ...
Henrik Bengtsson (max 7Mb