The environment variables "TMPDIR", "TMP", and "TEMP" can be used to change the value returned by tempdir() if the variable C R_TempDir not set (although I'm not sure how it is ready). If you need a cross-platform function that returns the path to a sensible tmp directory and is not interested in the value of R_TempDir , you can 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 InitTempDir function in the src / main / sysutils.c file from the source R, translated from C to R.
source share