[R] Cannot change location of tempdir()

Berend Hasselman bhh at xs4all.nl
Thu Mar 8 12:32:53 CET 2012

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


and see if that works.


More information about the R-help mailing list