cross platform - Read system TMP dir in R -
what cross-platform method find os temporary directory within r? use:
dirname(tempdir())
which did job both on ubuntu , windows within interactive r session. however, failed when called inside rapache. in rapache value of tempdir()
/tmp
, dirname(tempdir())
results in /
, wrong. tried:
sys.getenv("tmp") sys.getenv("temp") sys.getenv("tmpdir")
as suggested ?"environment variables"
none of these set in ubuntu. doesn't seem set in of files in /etc/r/*
don't quite understand how r detects value.
the environment variables "tmpdir", "tmp", , "temp" can used modify value returned tempdir()
if c variable r_tempdir
isn't set (although i'm not sure how done). if want cross-platform function return path of reasonable tmp directory, , aren't interested in value of r_tempdir
, use 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 based on function inittempdir
in file src/main/sysutils.c r source distribution, translated c r.
Comments
Post a Comment