Skip to content
Prev 17487 / 29559 Next

R crashes when looping with function writeRaster

Romolo,

For your questions about memory, please read vignette('raster').
probably yes, because you are loading all the values into RAM if you do that.
Consider doing something like this:

fileDisp=list.files(getwd())
for (f in 1:length(fileDisp))  :
      r <- raster(fileDisp[f])
   # never overwrite your input files!
   # preferably also send the output to another directory
     outf <- paste0(extension(fileDisp, ''), "_out.tif"
     x <- calc(r, function(x){ x[x <= -2000] <- NA;  x/10000 }, filename=outf)
}


# or perhaps

fileDisp=list.files(getwd())
for (f in 1:length(fileDisp))  :
      r <- raster(fileDisp[f])
     NAvalue(r) <- -2000
     outf <- paste0(extension(fileDisp, ''), "_out.tif"
     x <- calc(r, function(x)  x/10000, filename=outf)
}


Robert
On Thu, Feb 14, 2013 at 12:35 AM, Romolo Salini <salinir at tiscali.it> wrote: