Skip to content

terra::app

2 messages · Jonathan Thayn, Bede-Fazekas Ákos

#
I keep getting the following message when using terra:app ?? Error: [app] the number of values returned by 'fun' is not appropriate. I can?t figure out what I?m doing wrong. A sample code is below:




library(terra)
the.raster <- rast(ncol=4,nrow=4)
the.raster[] <- sample(0:65535,16)

get.snow <- function(j){
k <- as.numeric(intToBits(j)[10:11])
m <- k%*%1:2
return(m)
}

new.raster <- app(the.raster,get.snow)
#
Dear Jonathan,

Function get.snow() is not vectorized, i.e. it does not return a vector 
of the same length as its input. According to the help of app(), "The 
function should return a vector or matrix that is divisible by ncell(x).".

HTH,
?kos Bede-Fazekas
Centre for Ecological Research
Hungary

2022.09.29. 5:27 keltez?ssel, Thayn, Jonathan ?rta: