Skip to content
Prev 20990 / 29559 Next

What does the error "ERROR in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply): cannot use this function" mean in R?

As the error message says the error comes from testing your function on a
subset of your raster stack/brick i.e. x[1:5].
See below for a small example:

require(raster)
# create data
r <- raster(nrow=10, ncol=10)
s1 <- list()
for (i in 1:20) {
  s1[i] <- setValues(r, rnorm(ncell(r), i, 3) )
}
s1 <- stack(s1)

f_lowess <- function(x){
  df <- data.frame(t = 1:20, x)
  out <- lowess(df, f = .2)$y
  return(out)
}

## calc with a function
s2 <- calc(s1, fun = f_lowess)

## calc test - tests your function on a subset of the data
d <- s1[1:5] ## every row is a pixel
apply(d, 1, f_lowess) ## here no error occurs.



---
Jan Verbesselt
Wageningen University
The Netherlands
www.wageningenur.nl/changemonitor
On 07/05/14 11:51, "Bandrush Barda" <ndugarsuren at gmail.com> wrote: