Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename tar_<filetype>() to tar_<pkg>_<data type>() #7

Merged
merged 27 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
^\.github$
^codecov\.yml$
^LICENSE\.md$

^_targets$
^_targets_r$
^_targets\.R$
^_targets_packages\.R$
^_targets\.Rmd$
^_targets\.yaml$
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
.httr-oauth
.DS_Store
.quarto
.Rprofile

_targets_packages.R
_targets
_targets.R
_targets.Rmd
_targets_r
_targets.yaml
8 changes: 8 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Authors@R: c(
family = "Scott",
role = c("aut"),
comment = c(ORCID = "0000-0002-7430-7879")
),
person(
given = "Andrew",
family = "Brown",
role = c("aut"),
comment = c(ORCID = "0000-0002-4565-533X")
)
)
Description: Provides extensions for various geospatial file formats,
Expand All @@ -30,6 +36,8 @@ Imports:
terra
Suggests:
testthat (>= 3.0.0)
Depends:
R (>= 4.1.0)
Config/testthat/edition: 3
URL: https://github.com/njtierney/geotargets
BugReports: https://github.com/njtierney/geotargets/issues
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(tar_terra_rast)
export(tar_terra_vect)
importFrom(utils,globalVariables)
65 changes: 0 additions & 65 deletions R/tar-geotiff.R

This file was deleted.

86 changes: 0 additions & 86 deletions R/tar-shapefile.R

This file was deleted.

89 changes: 89 additions & 0 deletions R/tar-terra-rast.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#' Targets format for terra rasters
#'
#' Provides targets format for `terra::rast`
#'
#' @inheritParams targets::tar_target
#'
#' @export
#' @examples
#' 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)
#' })
#'}
tar_terra_rast <- function(name,
command,
pattern = NULL,
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"),
iteration = targets::tar_option_get("iteration"),
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")) {
name <- targets::tar_deparse_language(substitute(name))

envir <- targets::tar_option_get("envir")

command <- targets::tar_tidy_eval(
expr = as.expression(substitute(command)),
envir = envir,
tidy_eval = tidy_eval
)
pattern <- targets::tar_tidy_eval(
expr = as.expression(substitute(pattern)),
envir = envir,
tidy_eval = tidy_eval
)

format_terra_rast_geotiff <- targets::tar_format(
read = function(path) terra::rast(path),
write = function(object, path) {
terra::writeRaster(
x = object,
filename = path,
overwrite = TRUE,
filetype = "GTiff"
)
},
marshal = function(object) terra::wrap(object),
unmarshal = function(object) terra::unwrap(object)
)

targets::tar_target_raw(
name = name,
command = command,
pattern = pattern,
packages = packages,
library = library,
format = format_terra_rast_geotiff,
repository = repository,
iteration = iteration,
error = error,
memory = memory,
garbage_collection = garbage_collection,
deployment = deployment,
priority = priority,
resources = resources,
storage = storage,
retrieval = retrieval,
cue = cue
)
}
Loading