# NOT RUN {
r <- rast(system.file("ex/logo.tif", package="terra"))
set.seed(0)
r[[1]] <- flip(r[[1]], "horizontal")
r[[2]] <- flip(r[[2]], "vertical") + init(rast(r,1), runif)
r[[3]] <- init(rast(r,1), runif)
x <- focalCor(r, w=5, cor)
# suppress warning "the standard deviation is zero"
x <- focalCor(r, w=5, function(x, y) suppressWarnings(cor(x, y)))
# this does not happen when using a larger window
x <- focalCor(r, w=9, function(x, y) cor(x, y))
plot(x)
# }
Run the code above in your browser using DataLab