On 08-Mar-12 12:45, Prof Brian Ripley wrote:
> On Thu, 8 Mar 2012, Jon Olav Skoien wrote:
>
>> Hi,
>>
>> One of the functions I use needs to write to a temporary file, in the 
>> directory given by tempdir(). I want to change this from the standard 
>> one, as the file is too large for the drive. However, tempfile() 
>> doesnt seem to respect the environment variables when I change them 
>> with Sys.setenv(). In a fresh R-session:
>
> Who said it would?  By the time you set these, tempdir() is already 
> created.
>
> Set TMPDIR before you start R, e.g. on the RGui command line.

Thanks, that worked.
I guess I should have understood from the value-description of tempfile 
in the help-file that the temporary directory does not change:
"For |tempdir|, the path of the per-session temporary directory."
An addition to this sentence like:
"The directory is created at startup"
would maybe make it even clearer that in-session changes of the 
environment variables will not affect future calls to tempdir().

Regards,
Jon



>
>>
>>> Sys.getenv("TMP")
>> [1] "C:\\Users\\skoiejo\\AppData\\Local\\Temp"
>>>  Sys.setenv(TMP = "e:\\Temp\\Rtmp")
>>> Sys.getenv("TMP")
>> [1] "e:\\Temp\\Rtmp"
>>>  tempfile()
>> [1] "C:\\Users\\skoiejo\\AppData\\Local\\Temp\\Rtmp2tvQ7U\\file499a5987"
>> # I have also tried to change "TMPDIR", "TEMP" and "R_USER", all with 
>> the same result.
>>
>> # The directory is writable:
>>> write("some text", file = paste(Sys.getenv("TMP"),"test.txt",sep = ""))
>>> list.files(Sys.getenv("TMP"))
>> [1] "test.txt"
>>
>> I have probably misunderstood something, but what? Session info below.
>>
>>> sessionInfo()
>> R version 2.14.0 (2011-10-31)
>> Platform: x86_64-pc-mingw32/x64 (64-bit)
>>
>> locale:
>> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United 
>> States.1252    LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C                           LC_TIME=English_United 
>> States.1252
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.14.0
>>
>> I know this is not the last version, but I do not have administrator 
>> rights myself on the computer and did not see any relevant references 
>> to tempfile() in the news for newer versions.
>>
>> Thanks,
>> Jon
>>
>>
>


-- 
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Land Resource Management Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.skoien@jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.



	[[alternative HTML version deleted]]

