The environment variables "TMPDIR", "TMP", and "TEMP" can be used to modify the value returned by tempdir()
if the C variable R_TempDir
isn't set (although I'm not sure how that is done). If you want a cross-platform function that will return the path of a reasonable tmp directory, and aren't interested in the value of R_TempDir
, you could use something like this:
gettmpdir <- function() {
tm <- Sys.getenv(c('TMPDIR', 'TMP', 'TEMP'))
d <- which(file.info(tm)$isdir & file.access(tm, 2) == 0)
if (length(d) > 0)
tm[[d[1]]]
else if (.Platform$OS.type == 'windows')
Sys.getenv('R_USER')
else
'/tmp'
}
This is based on the function InitTempDir
in the file src/main/sysutils.c from the R source distribution, translated from C to R.