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

Verbesselt, Jan jan.verbesselt at wur.nl
Thu May 8 19:11:47 CEST 2014


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:

>I have a problem with lowess function to predict NDVI as a function of
>time
>by polynomial regression in R. NDVI image is 8-day image from Apr to Oct
>in
>Julian date of 97 to 297. Here is the scripts I run:
> 
>#Created a time vector to act as x
>time<-sort(sample(97:297, nlayers(ndvi2000crop1)))
>
>#locally-weighted polynomial regression of ndvi ~ time
>t.lowess <- function(x,...) { if (is.na(x[1])) {NA} else
>{lowess(x,y,...)$y
>} } 
>f.pred <- calc(ndvi2000crop1, t.lowess)
>
>When I calculate the function on image by doing the last step of this
>code,
>an error appeared something like this "Error in .calcTest(x[1:5], fun,
>na.rm, forcefun, forceapply): cannot use this function". Can you tell me
>where this error comes from and how to solve it?
>
>Thank you
>
>
>
>
>--
>View this message in context:
>http://r-sig-geo.2731867.n2.nabble.com/What-does-the-error-ERROR-in-calcTe
>st-x-1-5-fun-na-rm-forcefun-forceapply-cannot-use-this-function-m-tp758638
>4.html
>Sent from the R-sig-geo mailing list archive at Nabble.com.
>
>_______________________________________________
>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