Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change temporary directory

Tags:

r

tempdir

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
like image 751
Miguel Vazq Avatar asked Jun 14 '13 11:06

Miguel Vazq


People also ask

How do I change my temp folder?

Create a folder named "Temp" where you want the new folder to be located,(if you haven't already done so). Click on "Temp" Variable and click "Edit...". Enter new Variable Value (the location of your new folder; e.g "C:\Temp") and Click OK. Select "TMP" Variable and change it's value to the same folder).


3 Answers

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'))
like image 52
Matthew Plourde Avatar answered Oct 13 '22 20:10

Matthew Plourde


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.

like image 38
Adrian Stoica Avatar answered Oct 13 '22 20:10

Adrian Stoica


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.

like image 28
Chong Tang Avatar answered Oct 13 '22 20:10

Chong Tang