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

use linter, based off of targets linter #145

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
linters: linters_with_defaults(
infix_spaces_linter = NULL,
object_length_linter = NULL,
object_name_linter = NULL,
object_usage_linter = NULL,
indentation_linter = NULL)
exclusions: list("inst/notes/preserver_metadata_benchmarking.Qmd")
encoding: "UTF-8"
9 changes: 5 additions & 4 deletions R/geotargets-option.R
Original file line number Diff line number Diff line change
@@ -64,15 +64,16 @@ geotargets_option_set <- function(gdal_raster_driver = NULL,
gdal_vector_driver = NULL,
gdal_vector_creation_options = NULL,
terra_preserve_metadata = NULL) {
# TODO do this programmatically with formals() or something? `options()` also accepts a named list
# TODO do this programmatically with formals() or something?
# `options()` also accepts a named list
options(
"geotargets.gdal.raster.driver" = gdal_raster_driver %||%
"geotargets.gdal.raster.driver" = gdal_raster_driver %||% # nolint
geotargets_option_get("gdal.raster.driver"),
"geotargets.gdal.raster.creation.options" = gdal_raster_creation_options %||%
"geotargets.gdal.raster.creation.options" = gdal_raster_creation_options %||% # nolint
geotargets_option_get("gdal.raster.creation.options"),
"geotargets.gdal.vector.driver" = gdal_vector_driver %||%
geotargets_option_get("gdal.vector.driver"),
"geotargets.gdal.vector.creation.options" = gdal_vector_creation_options %||%
"geotargets.gdal.vector.creation.options" = gdal_vector_creation_options %||% #nolint
geotargets_option_get("gdal.vector.creation.options"),
"geotargets.terra.preserve.metadata" = terra_preserve_metadata %||%
geotargets_option_get("terra.preserve.metadata")
5 changes: 3 additions & 2 deletions R/release_bullets.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# see ?usethis::use_release_issue()
# see ?usethis::use_release_issue() #nolint
release_bullets <- function() {
c(
"update CITATION.cff with `cffr::cff_write(dependencies = FALSE)` (after incrementing version)"
"update CITATION.cff with `cffr::cff_write(dependencies = FALSE)`
(after incrementing version)"
)
}
152 changes: 80 additions & 72 deletions R/tar-stars.R
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@
#' `tar_stars()` has the same limitations as [stars::write_stars()], so use with
#' caution.
#'
#' @param 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 [targets::tar_target()]
#' for more information.
#' @param 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
#' [targets::tar_target()] for more information.
#' @param command R code to run the target.
#' @param pattern Code to define a dynamic branching pattern for a target. See
#' [targets::tar_target()] for more information.
@@ -45,37 +45,41 @@
#' list(
#' geotargets::tar_stars(
#' stars_example,
#' stars::read_stars(system.file("tif", "olinda_dem_utm25s.tif", package = "stars"))
#' stars::read_stars(
#' system.file("tif", "olinda_dem_utm25s.tif", package = "stars")
#' )
#' )
#' )
#' })
#' targets::tar_make()
#' x <- targets::tar_read(stars_example)
#' })
#' }
tar_stars <- function(name,
command,
pattern = NULL,
proxy = FALSE,
mdim = FALSE,
ncdf = FALSE,
driver = geotargets_option_get("gdal.raster.driver"),
options = geotargets_option_get("gdal.raster.creation.options"),
...,
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")) {
tar_stars <- function(
name,
command,
pattern = NULL,
proxy = FALSE,
mdim = FALSE,
ncdf = FALSE,
driver = geotargets_option_get("gdal.raster.driver"),
options = geotargets_option_get("gdal.raster.creation.options"),
...,
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")
) {
check_pkg_installed("stars")
if (ncdf) {
check_pkg_installed("ncmeta")
@@ -124,28 +128,30 @@ tar_stars <- function(name,

#' @export
#' @rdname tar_stars
tar_stars_proxy <- function(name,
command,
pattern = NULL,
mdim = FALSE,
ncdf = FALSE,
driver = geotargets_option_get("gdal.raster.driver"),
options = geotargets_option_get("gdal.raster.creation.options"),
...,
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")) {
tar_stars_proxy <- function(
name,
command,
pattern = NULL,
mdim = FALSE,
ncdf = FALSE,
driver = geotargets_option_get("gdal.raster.driver"),
options = geotargets_option_get("gdal.raster.creation.options"),
...,
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")
) {
check_pkg_installed("stars")
if (ncdf) {
check_pkg_installed("ncmeta")
@@ -196,29 +202,31 @@ tar_stars_proxy <- function(name,

#' tar_stars method with no tidy eval etc.
#' @noRd
tar_stars_raw <- function(name,
command,
pattern = NULL,
proxy,
mdim = FALSE,
ncdf = FALSE,
driver = geotargets_option_get("gdal.raster.driver"),
options = geotargets_option_get("gdal.raster.creation.options"),
...,
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")) {
tar_stars_raw <- function(
name,
command,
pattern = NULL,
proxy,
mdim = FALSE,
ncdf = FALSE,
driver = geotargets_option_get("gdal.raster.driver"),
options = geotargets_option_get("gdal.raster.creation.options"),
...,
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")
) {
driver <- driver %||% "GTiff"
options <- options %||% character(0)

65 changes: 38 additions & 27 deletions R/tar-terra-rast.R
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@
#' the `SpatRaster` object itself.
#'
#'
#' @param 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 [targets::tar_target()] for more information.
#' @param 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
#' [targets::tar_target()] for more information.
#' @param command R code to run the target.
#' @param pattern Code to define a dynamic branching pattern for a target. See
#' [targets::tar_target()] for more information.
@@ -56,27 +56,29 @@
#' x <- targets::tar_read(terra_rast_example)
#' })
#' }
tar_terra_rast <- function(name,
command,
pattern = NULL,
filetype = geotargets_option_get("gdal.raster.driver"),
gdal = geotargets_option_get("gdal.raster.creation.options"),
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")) {
tar_terra_rast <- function(
name,
command,
pattern = NULL,
filetype = geotargets_option_get("gdal.raster.driver"),
gdal = geotargets_option_get("gdal.raster.creation.options"),
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")
) {
filetype <- filetype %||% "GTiff"

# check that filetype option is available
@@ -114,10 +116,18 @@ tar_terra_rast <- function(name,
library = library,
format = targets::tar_format(
read = tar_rast_read(preserve_metadata = preserve_metadata),
write = tar_rast_write(filetype = filetype, gdal = gdal, preserve_metadata = preserve_metadata),
write = tar_rast_write(
filetype = filetype,
gdal = gdal,
preserve_metadata = preserve_metadata
),
marshal = function(object) terra::wrap(object),
unmarshal = function(object) terra::unwrap(object),
substitute = list(filetype = filetype, gdal = gdal, preserve_metadata = preserve_metadata)
substitute = list(
filetype = filetype,
gdal = gdal,
preserve_metadata = preserve_metadata
)
),
repository = repository,
iteration = "list", # only "list" works right now
@@ -151,7 +161,8 @@ tar_rast_read <- function(preserve_metadata) {
tar_rast_write <- function(filetype, gdal, preserve_metadata) {
switch(preserve_metadata,
zip = function(object, path) {
# write the raster in a fresh local tempdir() that disappears when function is done
# write the raster in a fresh local tempdir() that disappears when
# function is done
tmp <- withr::local_tempdir()
raster_tmp_file <- file.path(tmp, basename(path))
zip_tmp_file <- file.path(tmp, "object.zip")
Loading