Skip to content
Prev 10562 / 29559 Next

memory issues w/ raster processing

Marcia,

If the problem persists you can try to force it to write to disk if it does not.

setOptions(todisk=TRUE)

If it still fails:

setOptions(chunksize=100000)


I would normally not recommend to use these options.

The below worked for me (also with your number of rows and columns,
but then it takes a while!)

library(raster)

s <- list()
r <- raster(ncol=26, nrow=29)
for (i in 1:10) {
	s[i] <- setValues(r, round(runif(ncell(r)+0.5) * 3))
}
s <- stack(s)

f.232 = function(x){
   # adapted from code by Robert Hijmans
   # changes 232  to 222, but does not touch 233 or 223
   a <- which(x == 3)
   a <- subset(a, a > 1 & a < length(x))
   b <- which(x[a-1] == 2 & x[a+1] == 2)
   x[a[b]] <- 2
   return(x)
}

x <- calc(s, f.232)


On Wed, Dec 29, 2010 at 10:00 AM, Marcia Macedo
<marcia.n.macedo at gmail.com> wrote: