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
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.