From rgentlem@jimmy.harvard.edu  Fri Mar  8 21:54:10 2002
From: rgentlem@jimmy.harvard.edu (Robert Gentleman)
Date: Fri, 8 Mar 2002 16:54:10 -0500
Subject: [Rd] Sys.putenv environment variables disappear (PR#1371)
In-Reply-To: <200203082136.WAA01499@pubhealth.ku.dk>; from a215020@onyx.fmr.com on Fri, Mar 08, 2002 at 10:36:49PM +0100
References: <200203082136.WAA01499@pubhealth.ku.dk>
Message-ID: <20020308165410.X11590@jimmy.harvard.edu>

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.


> The loop prints "ok" twice, then exits because HOME has been destroyed.
> 
> I'm running R-1.4.1 (I also saw this in earlier versions), under
> Solaris 2.6.  Dave Kane reported this problem to R-help on 6/4/01, and
> I reported it on 11/30/01, but nobody else has confirmed (or denied)
> seeing it (except Kjetil Halvorsen did not see it on Windows).
> 
> FYI, my include/config.h file has "#define HAVE_PUTENV 1".  Here's the
> usual version info.
> Version:
>  platform = sparc-sun-solaris2.6
>  arch = sparc
>  os = solaris2.6
>  system = sparc, solaris2.6
>  status = 
>  major = 1
>  minor = 4.1
>  year = 2002
>  month = 01
>  day = 30
>  language = R
> 
> Search Path:
>  .GlobalEnv, package:misc, package:io, package:arrays, package:ls1, package:g.data, package:db, package:ts, package:ctest, Autoloads, package:base
> 
>                               -- David Brahm (brahm@alum.mit.edu)
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
+---------------------------------------------------------------------------+
| Robert Gentleman                 phone : (617) 632-5250                   |
| Associate Professor              fax:   (617)  632-2444                   |
| Department of Biostatistics      office: M1B28
| Harvard School of Public Health  email: rgentlem@jimmy.dfci.harvard.edu   |
+---------------------------------------------------------------------------+
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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)
Robert Gentleman