On 08-03-2012, at 12:15, 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: > > > 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.
>From the help for Sys.setenv: Sys.setenv sets environment variables (for other processes called from within R or future calls to Sys.getenv from this R process). You should try tempfile(tmpdir=Sys.getenv("TMP")) and see if that works. Berend ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.