问题
I am using R on windows and need to change the temporary directory where tmp files are stored.
I checked a few answers, here, in R-help, etc., but no one is working.
Some links I tried: here, here, and here.
After trying those answers (I have to say that I do not get exactly the point on them),
tempdir()
still is the default, as much as I try different ways.
Can anybody can give a detailed example procedure of how to do this?
My session Info:
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_2.15.2
回答1:
Create a file called .Renviron in the directory given by Sys.getenv('R_USER')
and save it with the line TMP = '<your-desired-tempdir>'
.
write("TMP = '<your-desired-tempdir>'", file=file.path(Sys.getenv('R_USER'), '.Renviron'))
回答2:
In windows, for me what worked is creating a file named Renviron.site and filling it with
TMPDIR=E:/rtemp
TMP=E:/rtemp
TEMP=E:/rtemp
Where E:/rtemp was the path to the directory where I wanted the temporary files. So you create a new text file, fill it with the above, and change its name (and extension) to Renviron.site.
Put it inside the R installation directory, in the directory etc (e.g. C:\Program Files\R\R-3.3.2\etc)
Obviously, you need to restart R studio for the change to work! (I use R studio but it should work in R also).
For me, this change allowed me to run a script of species distribution modeling which was creating very large temporary files on the system partition, consuming all the space and killing the process in the end. I have moved the temp files to a usb SSD disk (partition E:), and voila, it worked.
PS - the answer was in one of the links you mentioned.
回答3:
For Linux, I'm using Ubuntu 18.04.1 LTS. You can try the following line:
write("TMP = YOUR_PATH_VARIABLE", file=file.path('~/.Renviron'))
Explanation: This line will write the TMP variable, which has been assigned to your own temp path, to the '.Renviron' file. And this '.Renviron' file will be created in your home directory. If this doesn't work, restart your R or R studio. The reason is the temporary directory was created before the current R session. So you have to restart another R session to implement this new TEMP_PATH configuration.
来源:https://stackoverflow.com/questions/17107206/change-temporary-directory