Skip to content

Commit

Permalink
Merge pull request #145 from njtierney/use-lintr-i144
Browse files Browse the repository at this point in the history
use linter, based off of targets linter. Resolves #144
  • Loading branch information
njtierney authored Jan 17, 2025
2 parents 56c84fe + dc3ba95 commit 22dd055
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 268 deletions.
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
Expand Up @@ -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")
Expand Down
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
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
65 changes: 38 additions & 27 deletions R/tar-terra-rast.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 22dd055

Please sign in to comment.