From ripley@stats.ox.ac.uk  Sat Mar  9 07:32:55 2002
From: ripley@stats.ox.ac.uk (Prof Brian D Ripley)
Date: Sat, 9 Mar 2002 07:32:55 +0000 (GMT)
Subject: [Rd] Sys.putenv environment variables disappear (PR#1371)
In-Reply-To: <20020308165410.X11590@jimmy.harvard.edu>
Message-ID: <Pine.GSO.4.44.0203090726550.3971-100000@auk.stats>

On Fri, 8 Mar 2002, Robert Gentleman wrote:

> On Fri, Mar 08, 2002 at 10:36:49PM +0100, a215020@onyx.fmr.com wrote:
> > Environment variables set with Sys.putenv() disappear (i.e. become "")
> > after a while, especially after heavy-duty I/O.  Example:
> >
> >   R> x <- matrix(1., 3000, 3000)
> >   R> save(x, file="myx.RData")
> >   R> Sys.putenv(HOME="/tmp")
> >   R> while (Sys.getenv("HOME") != "") {cat("ok\n"); load("myx.RData")}
> >
>
>   We use
>    for (i = 0; i < n; i++) {
>         LOGICAL(ans)[i] = putenv(CHAR(STRING_ELT(vars, i))) == 0;
>     }
>  and the man page for RedHat says:
>          int putenv(const char *string);
>
> DESCRIPTION
>        The  putenv()  function adds or changes the value of envi-
>        ronment variables.  The argument string  is  of  the  form
>        name=value.   If  name does not already exist in the envi-
>        ronment, then string is added to the environment.  If name
>        does  exist,  then the value of name in the environment is
>        changed to value.  The string pointed to by string becomes
>        part  of  the  environment, so altering the string changes
>        the environment.
>
>   So, after we UNPROTECT this is bad. Seems like we need to
>   do something different.

And what is needed is in the function Putenv in the same file, since
environment variables read from startup files are working correctly.

I've copied the code across (actually from the Windows version).

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Sys.putenv environment variables disappear (PR#1371)
Prof Brian D Ripley