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) and restart RStudio or R.