Hack-R Hack-R - 2 months ago 5x
R Question

Rscript uses C:/ for temp files even though TMP and TMPDIR set to another drive

My .Renviron file specifies

TMP = 'F:\temp'
TMPDIR = 'F:\temp'

and in RStudio I get the following results:


[1] "F:\temp"


[1] "F:\temp"

That part is the way it should be. I have 1 TB of free space on F:/ and less than 50 MB free on C:/.

However, when I run a script via Rscript as a scheduled task it always fails because it somehow reverts to trying to use the C:/ for temporary files and runs out of space.

How can I fix this?

In the current use case the major user of temp files is
from the package
. I tried setting
in that function call, but it made no difference.


Set them system-wide via the System Properties --> Environment Variables so they are set before R is started. That is what Rstudio accomplished: it runs as a GUI/IDE before it launches the underlying R process.

Windows Illustration: enter image description here

Linux Illustration:

edd@max:~$ TMP=/opt TEMPDIR=/src Rscript -e \   # line broken for display only
                       'print(Sys.getenv("TMP")); print(Sys.getenv("TEMPDIR"))'
[1] "/opt"
[1] "/src"