[R] Problem setting TMPDIR on the fly

Duncan Murdoch murdoch at stats.uwo.ca
Mon Oct 30 19:20:48 CET 2006


On 10/30/2006 11:22 AM, Benjamin Lloyd-Hughes wrote:
> Hi folks,
> 
>  
> 
> I'm having a spot of bother with tempdir().  If I set the environment
> variable TMPDIR in my shell prior to invoking R it works as expected:
> 
>  
> 
>> Sys.getenv("TMPDIR")
> 
>               TMPDIR 
> 
> "/eurotempest/tmp/R" 
> 
>> tempdir()
> 
> [1] "/eurotempest/tmp/R/Rtmp0xY4XD"
> 
>  
> 
> However if I don't set it prior to entry, but attempt to set it from
> within the current session, the change is not detected/respected:
> 
>  
> 
>> Sys.getenv("TMPDIR")
> 
> TMPDIR 
> 
>     "" 
> 
>> Sys.putenv(TMPDIR = "/eurotempest/tmp/R/")
> 
>> Sys.getenv("TMPDIR")
> 
>                TMPDIR 
> 
> "/eurotempest/tmp/R/" 
> 
>> tempdir()
> 
> [1] "/tmp/Rtmp9chsNX"
> 
>  
> 
> Any ideas?

It's behaving as designed.  It reads the environment variable upon 
startup, and then uses that directory for the whole session.  (This 
allows it to clean up at the end.  If you changed directories midway 
through, what would happen to temp files in the old directory?)

Duncan Murdoch



More information about the R-help mailing list