2

I'm desperately trying to writeRaster() but, since the raster is quite large I need a lot of temp memory. The space on my C:/ drive is limited and therefore I want to change the temporary dir to D:/TEMP/. I tried different approaches I found on the Internet like:

Change temporary directory

http://r.789695.n4.nabble.com/How-do-I-set-the-Windows-temporary-directory-in-R-td876483.html

etc.

rasterOptions(tmpdir = "D:/RTEMP/") didn't solve the problem. Even if it worked while the calculation of the raster, it doesn't affect the writeRaster() function.

I would be very thankful, if anybody can help me.

Here is my sessionInfo():

`R version 3.1.2 (2014-10-31)

Platform: x86_64-w64-mingw32/x64 (64-bit)`
Community
  • 1
  • 1
loki
  • 9,816
  • 7
  • 56
  • 82
  • Are you seriously writing raster objects bigger than your system's RAM, or are you not specifying a file name in writeRaster? – Oliver Keyes Dec 04 '14 at 21:08
  • The raster I want to write has 23GB in the temporary file of the `rasterOptions`. I am specifying a target file. When `writeRaster(r1glcm, "G://.tif", format = "GTiff", compression = "LZW", progress = "text")` The temp is written to C:/users/user/documents/ – loki Dec 04 '14 at 21:13

1 Answers1

5

I got to the right answer:

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

This changes even the temp-directory of the writeRaster() function

UPDATE:

for those of you, who might have trouble with this error (due to limited permissions)

> write("TMPDIR = D:/rtmp/", file=file.path(Sys.getenv('TMPDIR'), '.Renviron'))
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file '/.Renviron': Permission denied

i found that

rasterOptions(tmpdir = "D:/rtmp/")
write("R_USER = D:/rtmp/", file=file.path(Sys.getenv('R_USER'), '.Renviron'))

also solves the issue.

loki
  • 9,816
  • 7
  • 56
  • 82