[R-sig-Geo] R crashed when running calc

Robert J. Hijmans r.hijmans at gmail.com
Tue Feb 18 03:59:48 CET 2014


Eddie,
The function does not work (maxsst is not defined). You are not
providing sessionInfo()
You should be able to avoid memory problems (if that is what causes
this) via rasterOptions(chunksize=___)

E.g.,

rasterOptions(chunksize=1e+05)

Robert


On Mon, Feb 17, 2014 at 11:19 AM, Eddie Smith <eddieatr at gmail.com> wrote:
> Hi guys,
>
> Everytime I tried to run calc(), R crashed. Any advice?
> Here is my code:
>
> #clear memory/remove all R objects
> rm(list=ls())
>
> #check memory size and set memory limit
> memory.size()
> memory.limit(10000)
>
> #Load related packages library
> library(raster)
> library(rgdal)
>
> #Load all raster data in a folder
> img <- list.files(pattern='\\.img$')
>
> #Check rasters
> list(img)
>
> #Stack layers into one file
> flag7 <- stack(img)
>
> #2 CReate fun
> time <- 1:nlayers(flag7)
> fun <- function(x) {
> if (all(is.na(x))) {
> return(cbind(NA,NA,NA))
> }
> xcost<-cos(2*pi*time/366)
> xsine<-sin(2*pi*time/366)
> m = lm(x~xcost+xsine)
> s  <- summary(m)
> maxval <- max(predict(m))
> r2 <- s$r.squared
> sigma <- s$sigma
> cbind(maxsst, r2, sigma)
> }
>
> #3 Run function with rasterstack
> r <- calc(flag7, fun)
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list