I am trying to count the non-NA values in a spatRaster using the global()
function from the terra package. All the functions (mean, max, sd, etc.) seem to work except for "isNA"
and "notNA"
. For these two functions it returns this error: Error in fun(values(x[[i]]), ...) : could not find function "fun"
, which is the same error it returns for a misspelled/non-existent function.
r <- rast(ncols=10, nrows=10)
values(r) <- c(1:(ncell(r)-1),NA) # Add one NA value
global(r, fun="mean", na.rm=TRUE) # works
global(r, fun="notNA") # error
global(r, fun="notAfunction") # error
Interestingly, when looking at the documentation (?global
), the NA functions are named in the function description but are not listed specifically listed as argument options for fun
.
So can global()
count the NAs/non-NAs? Are the NA function names correct?
Edit: terra version: 1.4.22