# \donttest{
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
# not parallel
# Returned object is a VRT backed by per-tile files in tempdir().
out1 <- tile_apply(r, function(x) x * 2)
# focal, use a buffer wide enough for the focal window
out3 <- tile_apply(r, function(x) focal(x, w=5, fun="mean",
na.rm=TRUE), buffer=2)
# parallel on 2 workers
if (FALSE) {
out4 <- tile_apply(r, function(x) x * 2, cores=2)
# pass extra arguments by name; nested terra objects are auto-wrapped
out5 <- tile_apply(r, function(x, k) x * k, cores=2, tiles=50, k=10)
# use a future plan instead of a cluster
if (requireNamespace("future", quietly=TRUE) &&
requireNamespace("future.apply", quietly=TRUE)) {
future::plan(future::multisession, workers=2)
out6 <- tile_apply(r, function(x) x * 2, cores="future")
future::plan(future::sequential)
}
}
# }
Run the code above in your browser using DataLab