Permalink
Browse files

Allow specifying user environment and profile files via environment

variables 'R_ENVIRON_USER' and 'R_PROFILE_USER', respectively.

git-svn-id: https://svn.r-project.org/R/trunk@45053 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
1 parent 6ea6ec5 commit f3455ae392f6d01e6bb36d9bb05e995c2086a1ea hornik committed Apr 3, 2008
Showing with 51 additions and 31 deletions.
  1. +1 −1 doc/Rscript.1
  2. +17 −12 doc/manual/R-intro.texi
  3. +17 −11 src/library/base/man/Startup.Rd
  4. +6 −1 src/main/Renviron.c
  5. +1 −1 src/scripts/R.sh.in
  6. +1 −1 src/unix/Rscript.c
  7. +8 −4 src/unix/sys-unix.c
View
@@ -45,7 +45,7 @@ Don't read the site and user environment files
Don't read the site-wide Rprofile
.TP
\fB\-\-no\-init\-file\fR
-Don't read the .Rprofile or ~/.Rprofile files
+Don't read the user R profile
.TP
\fB\-\-restore\fR
Do restore previously saved objects at startup
View
@@ -4033,7 +4033,8 @@ users control over their workspace and allows for different startup
procedures in different working directories. If no @file{.Rprofile}
file is found in the startup directory, then @R{} looks for a
@file{.Rprofile} file in the user's home directory and uses that (if it
-exists).
+exists). If the environment variable @env{R_PROFILE_USER} is set, the
+file it points to is used instead of the @file{.Rprofile} files.
Any function named @code{.First()} in either of the two profile files or
in the @file{.RData} image has a special status. It is automatically
@@ -4043,7 +4044,7 @@ below alters the prompt to @code{$} and sets up various other useful
things that can then be taken for granted in the rest of the session.
Thus, the sequence in which files are executed is, @file{Rprofile.site},
-@file{.Rprofile}, @file{.RData} and then @code{.First()}. A definition
+the user profile, @file{.RData} and then @code{.First()}. A definition
in later files will mask definitions in earlier files.
@example
@@ -6797,13 +6798,15 @@ Unless @option{--no-environ} was given, @R{} searches for user and site
files to process for setting environment variables. The name of the
site file is the one pointed to by the environment variable
@env{R_ENVIRON}; if this is unset, @file{$R_HOME/etc/Renviron.site} is
-used (if it exists). The user file searched for is @file{.Renviron}
-in the current or in the user's home directory (in that order). These
-files should contain lines of the form @samp{@var{name}=@var{value}}.
-(See @code{help(Startup)} for a precise description.) Variables you
-might want to set include @env{R_PAPERSIZE} (the default paper size),
-@env{R_PRINTCMD} (the default print command) and @env{R_LIBS} (specifies
-the list of @R{} library trees searched for add-on packages).
+used (if it exists). The user file is the one pointed to by the
+environment variable @env{R_ENVIRON_USER} if this is set; otherwise,
+files @file{.Renviron} in the current or in the user's home directory
+(in that order) are searched for. These files should contain lines of
+the form @samp{@var{name}=@var{value}}. (See @code{help("Startup")} for
+a precise description.) Variables you might want to set include
+@env{R_PAPERSIZE} (the default paper size), @env{R_PRINTCMD} (the
+default print command) and @env{R_LIBS} (specifies the list of @R{}
+library trees searched for add-on packages).
@item
Then @R{} searches for the site-wide startup profile unless the command
@@ -6813,9 +6816,11 @@ that variable is unset, the default @file{$R_HOME/etc/Rprofile.site} is
used if this exists.
@item
-Then, unless @option{--no-init-file} was given, @R{} searches for a file
-called @file{.Rprofile} in the current directory or in the user's home
-directory (in that order) and sources it.
+Then, unless @option{--no-init-file} was given, @R{} searches for a user
+profile and sources it. The name of this file is taken from the
+environment variable @env{R_PROFILE_USER}; if unset, a file called
+@file{.Rprofile} in the current directory or in the user's home
+directory (in that order) is searched for.
@item
It also loads a saved image from @file{.RData} if there is one (unless
@@ -31,8 +31,10 @@
environment variable \env{R\_ENVIRON}; if this is unset or empty,
\file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron.site} is used (if it exists, which it
does not in a \sQuote{factory-fresh} installation).
- The user files searched for are \file{.Renviron} in the current or in
- the user's home directory (in that order).
+ The name of the user can be specified by the \env{R\_ENVIRON\_USER}
+ environment variable; if this is unset, the user files searched for are
+ \file{.Renviron} in the current or in the user's home directory (in
+ that order).
#ifdef windows
(See \sQuote{See also} for how the home directory is found on Windows.)
#endif
@@ -55,10 +57,12 @@
is normally advisable to use \code{\link{local}} if code needs to be
executed: see the examples.
- Then, unless \option{--no-init-file} was given, \R searches for a file
+ Then, unless \option{--no-init-file} was given, \R searches for a user
+ profile. The name of this file can be specified by the
+ \env{R\_PROFILE\_USER} environment variable. If this is unset, a file
called \file{.Rprofile} in the current directory or in the user's
- home directory (in that order) and sources it into the user
- workspace.
+ home directory (in that order) is searched for. The user profile is
+ sourced into the user workspace.
Note that when the site and user profile files are sourced only the
\pkg{base} package is loaded, so objects in other packages need to be
@@ -126,15 +130,17 @@
}
\note{
#ifdef unix
- The file \file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron} is always read very early in
- the start-up processing. It contains environment variables set by \R
- in the configure process. Values in that file can be overridden in
- site or user environment files: do not change
- \file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron} itself. Note that this is distinct from
+ The file \file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron} is
+ always read very early in the start-up processing. It contains
+ environment variables set by \R in the configure process. Values in
+ that file can be overridden in site or user environment files: do not
+ change \file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron} itself.
+ Note that this is distinct from
\file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron.site}.
#endif
#ifdef windows
- Unix versions of \R have a file \file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron}
+ Unix versions of \R have a file
+ \file{\var{\link[base:Rhome]{R\_HOME}}/etc/Renviron}
which is read very early in the start-up processing. It contains
environment variables set by \R in the configure process, and is not
used on \R for Windows.
View
@@ -255,7 +255,12 @@ void process_site_Renviron ()
/* try user Renviron: ./.Renviron, then ~/.Renviron */
void process_user_Renviron()
{
- const char *s;
+ const char *s = getenv("R_ENVIRON_USER");
+
+ if(s && strlen(s)) {
+ process_Renviron(R_ExpandFileName(s));
+ return;
+ }
if(process_Renviron(".Renviron")) return;
#ifdef Unix
View
@@ -61,7 +61,7 @@ Options:
--no-save Don't save it
--no-environ Don't read the site and user environment files
--no-site-file Don't read the site-wide Rprofile
- --no-init-file Don't read the .Rprofile or ~/.Rprofile files
+ --no-init-file Don't read the user R profile
--restore Do restore previously saved objects at startup
--no-restore-data Don't restore previously saved objects
--no-restore-history Don't restore the R history file
View
@@ -89,7 +89,7 @@ void usage(void)
fprintf(stderr, " --save Do save workspace at the end of the session\n");
fprintf(stderr, " --no-environ Don't read the site and user environment files\n");
fprintf(stderr, " --no-site-file Don't read the site-wide Rprofile\n");
- fprintf(stderr, " --no-init-file Don't read the .Rprofile or ~/.Rprofile files\n");
+ fprintf(stderr, " --no-init-file Don't read the user R profile\n");
fprintf(stderr, " --restore Do restore previously saved objects at startup\n");
fprintf(stderr, " --vanilla Combine --no-save, --no-restore, --no-site-file\n");
fprintf(stderr, " --no-init-file and --no-environ\n");
View
@@ -59,17 +59,21 @@ extern Rboolean LoadInitFile;
attribute_hidden
FILE *R_OpenInitFile(void)
{
- char buf[256], *home;
+ char buf[256], *home, *p = getenv("R_PROFILE_USER");
FILE *fp;
fp = NULL;
if (LoadInitFile) {
- if ((fp = R_fopen(".Rprofile", "r")))
+ if(p && strlen(p)) {
+ fp = R_fopen(R_ExpandFileName(p), "r");
return fp;
- if ((home = getenv("HOME")) == NULL)
+ }
+ if((fp = R_fopen(".Rprofile", "r")))
+ return fp;
+ if((home = getenv("HOME")) == NULL)
return NULL;
sprintf(buf, "%s/.Rprofile", home);
- if ((fp = R_fopen(buf, "r")))
+ if((fp = R_fopen(buf, "r")))
return fp;
}
return fp;

0 comments on commit f3455ae

Please sign in to comment.