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 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.httr-oauth
.DS_Store
.quarto
.Rprofile
11 changes: 5 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ Version: 0.0.0.9000
Authors@R: c(
person(
given = "Nicholas",
last = "Tierney",
family = "Tierney",
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "https://orcid.org/0000-0003-1460-8722")
comment = c(ORCID = "0000-0003-1460-8722")
),
person(
given = "",
last = "",
email = "",
given = "Eric",
family = "Scott",
role = c("aut"),
comment = c(ORCID = "https://orcid.org/XXXX")
comment = c(ORCID = "0000-0002-7430-7879")
)
)
Description: Provides extensions for various geospatial file formats,
Expand Down
17 changes: 17 additions & 0 deletions R/formats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
format_terra_rast <- function() {
write_fun <- function(object, path) {
terra::writeRaster(
x = object,
filename = path,
overwrite = TRUE,
filetype = "GTiff" #TODO would love to be able to control this with an argument to format_terra_rast()
)
}
Aariq marked this conversation as resolved.
Show resolved Hide resolved
targets::tar_format(
read = function(path) terra::rast(path),
write = write_fun,
marshal = function(object) terra::wrap(object),
unmarshal = function(object) terra::unwrap(object)
)
}

65 changes: 0 additions & 65 deletions R/tar-geotiff.R

This file was deleted.

54 changes: 54 additions & 0 deletions R/tar-terra.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' @export
tar_terra_rast <- function(name,
command,
pattern = NULL,
packages = targets::tar_option_get("packages"),
tidy_eval = targets::tar_option_get("tidy_eval"),
library = targets::tar_option_get("library"),
format = format_terra_rast(),
njtierney marked this conversation as resolved.
Show resolved Hide resolved
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
)

targets::tar_target_raw(
name = name,
command = command,
pattern = pattern,
packages = packages,
library = library,
format = format,
repository = repository,
iteration = iteration,
error = error,
memory = memory,
garbage_collection = garbage_collection,
deployment = deployment,
priority = priority,
resources = resources,
storage = storage,
retrieval = retrieval,
cue = cue
)
}
5 changes: 5 additions & 0 deletions tests/testthat/test-formats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test_that("formats return output of tar_format()", {
expect_type(format_terra_rast, "closure")
expect_type(format_terra_rast(), "character")
expect_match(format_terra_rast(), "^format_custom.+")
})