1

I'm working on a Windows machine and I would like to change the location where the temporary files are stored (from C: to G: drive).

I have tried doing so in three different ways:

write("TMPDIR = G:/temp", file=file.path(Sys.getenv('R_USER'), '.Renviron'))

or

tempfile(pattern = ".Renviron", tmpdir = "G:/temp")

or

tempfile(tmpdir = "G:/temp")

but in each case when I go ahead and check with tempdir() I find that the location is still the initial one. What am I doing wrong?

g_puffo
  • 613
  • 3
  • 11
  • 21
  • 1
    Did you restart the application before checking the value? TMP or TEMP are environment variables. An application's environment is loaded on application start. Hence any change in environment variables is not reflexted till application restart – Ganesh R. Mar 12 '16 at 03:31
  • @GaneshR. yes I have. – g_puffo Mar 12 '16 at 03:40
  • See http://stackoverflow.com/questions/10322451/change-tempdir-in-session-update-r-tempdir and https://www.rforge.net/doc/packages/unixtools/set.tempdir.html – Ganesh R. Mar 12 '16 at 03:55
  • So, surprisingly, if I change the temporary directory in R and restart it, it doesn't work. However, if I change the temporary directory in R and I restart R studio instead, it does work. How is this possible? – g_puffo Mar 12 '16 at 04:01
  • May be the R code is hosted and executed in RStudio and not a separate executable – Ganesh R. Mar 12 '16 at 15:19

1 Answers1

0

Try as follows. It will probably work.

write("TMPDIR = G:\temp\", file=file.path(Sys.getenv('TMPDIR'), '.Renviron'))
write("R_USER = G:\temp\", file=file.path(Sys.getenv('R_USER'), '.Renviron'))
Abdullah Elen
  • 534
  • 4
  • 13