tar_terra_rast {geotargets} | R Documentation |
Create a terra SpatRaster target
Description
Provides a target format for terra::SpatRaster objects.
Usage
tar_terra_rast(
name,
command,
pattern = NULL,
filetype = geotargets_option_get("gdal.raster.driver"),
gdal = geotargets_option_get("gdal.raster.creation.options"),
datatype = geotargets_option_get("gdal.raster.data.type"),
preserve_metadata = geotargets_option_get("terra.preserve.metadata"),
...,
tidy_eval = targets::tar_option_get("tidy_eval"),
packages = targets::tar_option_get("packages"),
library = targets::tar_option_get("library"),
repository = targets::tar_option_get("repository"),
error = targets::tar_option_get("error"),
memory = targets::tar_option_get("memory"),
garbage_collection = targets::tar_option_get("garbage_collection"),
deployment = targets::tar_option_get("deployment"),
priority = targets::tar_option_get("priority"),
resources = targets::tar_option_get("resources"),
storage = targets::tar_option_get("storage"),
retrieval = targets::tar_option_get("retrieval"),
cue = targets::tar_option_get("cue"),
description = targets::tar_option_get("description")
)
Arguments
name |
Symbol, name of the target. A target name must be a valid name
for a symbol in R, and it must not start with a dot. See
|
command |
R code to run the target. |
pattern |
Code to define a dynamic branching pattern for a target. See
|
filetype |
character. File format expressed as GDAL driver names passed
to |
gdal |
character. GDAL driver specific datasource creation options
passed to |
datatype |
character. Data type passed to |
preserve_metadata |
character. When |
... |
Additional arguments passed to |
tidy_eval |
Logical, whether to enable tidy evaluation
when interpreting |
packages |
Character vector of packages to load right before
the target runs or the output data is reloaded for
downstream targets. Use |
library |
Character vector of library paths to try
when loading |
repository |
Character of length 1, remote repository for target storage. Choices:
Note: if |
error |
Character of length 1, what to do if the target stops and throws an error. Options:
|
memory |
Character of length 1, memory strategy. Possible values:
For cloud-based file targets
(e.g. |
garbage_collection |
Logical: |
deployment |
Character of length 1. If |
priority |
Deprecated on 2025-04-08 ( |
resources |
Object returned by |
storage |
Character string to control when the output of the target
is saved to storage. Only relevant when using
|
retrieval |
Character string to control when the current target
loads its dependencies into memory before running.
(Here, a "dependency" is another target upstream that the current one
depends on.) Only relevant when using
|
cue |
An optional object from |
description |
Character of length 1, a custom free-form human-readable
text description of the target. Descriptions appear as target labels
in functions like |
Details
The terra package uses objects like terra::SpatRaster,
terra::SpatVector, and terra::SpatRasterDataset (SDS), which do
not contain the data directly–they contain a C++ pointer to memory where
the data is stored. As a result, these objects are not portable between
R sessions without special handling, which causes problems when including
them in targets
pipelines with targets::tar_target()
. The functions,
tar_terra_rast()
, tar_terra_sds()
, tar_terra_sprc()
,
tar_terra_tiles()
, and tar_terra_vect()
handle this issue by writing and
reading the target as a geospatial file (specified by filetype
) rather
than saving the relevant object (e.g., SpatRaster
, SpatVector
, etc.),
itself.
Value
target class "tar_stem" for use in a target pipeline
Note
The iteration
argument is unavailable because it is hard-coded to
"list"
, the only option that works currently.
See Also
Examples
# For CRAN. Ensures these examples run under certain conditions.
# To run this locally, run the code inside this if statement
if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") {
targets::tar_dir({ # tar_dir() runs code from a temporary directory.
library(geotargets)
targets::tar_script({
list(
geotargets::tar_terra_rast(
terra_rast_example,
system.file("ex/elev.tif", package = "terra") |> terra::rast()
)
)
})
targets::tar_make()
x <- targets::tar_read(terra_rast_example)
})
}