Skip to content

Commit

Permalink
Merge pull request #85 from njtierney/iteration-list
Browse files Browse the repository at this point in the history
Hard code `iteration = "list"`
  • Loading branch information
Aariq authored Aug 19, 2024
2 parents 1be6d62 + 76ae2e8 commit ea1f9fe
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 94 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
Language: en-GB
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
targets (>= 1.7.0),
rlang (>= 1.1.3),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Created `tar_stars()` and `tar_stars_proxy()` that create `stars` and `stars_proxy` objects, respectively.
* Created `tar_terra_tiles()`, a "target factory" for splitting a raster into multiple tiles with dynamic branching.
* Removes the `iteration` argument from all `tar_*()` functions. `iteration` now hard-coded as `"list"` since it is the only option that works (for now at least).
* Created two helper functions for use in `tar_terra_tiles()`: `tile_grid()` and `tile_blocksize()`.
* Created utility function `set_window()` mostly for internal use within `tar_terra_tiles()`.
* Added the `description` argument to all `tar_*()` functions which is passed to `tar_target()`.
Expand Down
11 changes: 5 additions & 6 deletions R/tar-stars.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#' @param ... Additional arguments not yet used
#'
#' @inheritParams targets::tar_target
#'
#' @note The `iteration` argument is unavailable because it is hard-coded to
#' `"list"`, the only option that works currently.
#'
#' @seealso [targets::tar_target_raw()]
#' @export
#' @examplesIf rlang::is_installed("stars")
Expand Down Expand Up @@ -41,7 +45,6 @@ tar_stars <- function(name,
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"),
Expand Down Expand Up @@ -83,7 +86,6 @@ tar_stars <- function(name,
packages = packages,
library = library,
repository = repository,
iteration = iteration,
error = error,
memory = memory,
garbage_collection = garbage_collection,
Expand Down Expand Up @@ -111,7 +113,6 @@ tar_stars_proxy <- function(name,
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"),
Expand Down Expand Up @@ -154,7 +155,6 @@ tar_stars_proxy <- function(name,
packages = packages,
library = library,
repository = repository,
iteration = iteration,
error = error,
memory = memory,
garbage_collection = garbage_collection,
Expand Down Expand Up @@ -184,7 +184,6 @@ tar_stars_raw <- function(name,
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"),
Expand Down Expand Up @@ -264,7 +263,7 @@ tar_stars_raw <- function(name,
unmarshal = function(object) object
),
repository = repository,
iteration = iteration,
iteration = "list", #the only option that works
error = error,
memory = memory,
garbage_collection = garbage_collection,
Expand Down
7 changes: 5 additions & 2 deletions R/tar-terra-rast.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#' @param ... Additional arguments not yet used
#'
#' @inheritParams targets::tar_target
#'
#' @note The `iteration` argument is unavailable because it is hard-coded to
#' `"list"`, the only option that works currently.
#'
#' @returns target class "tar_stem" for use in a target pipeline
#' @importFrom rlang %||% arg_match0
#' @seealso [targets::tar_target_raw()]
Expand Down Expand Up @@ -39,7 +43,6 @@ tar_terra_rast <- function(name,
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"),
Expand Down Expand Up @@ -104,7 +107,7 @@ tar_terra_rast <- function(name,
unmarshal = function(object) terra::unwrap(object)
),
repository = repository,
iteration = iteration,
iteration = "list", #only "list" works right now
error = error,
memory = memory,
garbage_collection = garbage_collection,
Expand Down
7 changes: 5 additions & 2 deletions R/tar-terra-sprc.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#' @param ... Additional arguments not yet used
#'
#' @inheritParams targets::tar_target
#'
#' @note The `iteration` argument is unavailable because it is hard-coded to
#' `"list"`, the only option that works currently.
#'
#' @returns target class "tar_stem" for use in a target pipeline
#' @seealso [targets::tar_target_raw()]
#' @author Andrew Gene Brown
Expand Down Expand Up @@ -52,7 +56,6 @@ tar_terra_sprc <- function(name,
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"),
Expand Down Expand Up @@ -123,7 +126,7 @@ tar_terra_sprc <- function(name,
unmarshal = function(object) terra::unwrap(object)
),
repository = repository,
iteration = iteration,
iteration = "list",
error = error,
memory = memory,
garbage_collection = garbage_collection,
Expand Down
7 changes: 5 additions & 2 deletions R/tar-terra-vect.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#' passed to [terra::writeVector()].
#' @param ... Additional arguments not yet used
#' @inheritParams targets::tar_target
#'
#' @note The `iteration` argument is unavailable because it is hard-coded to
#' `"list"`, the only option that works currently.
#'
#' @returns target class "tar_stem" for use in a target pipeline
#'
#' @note Although you may pass any supported GDAL vector driver to the
Expand Down Expand Up @@ -48,7 +52,6 @@ tar_terra_vect <- function(name,
tidy_eval = targets::tar_option_get("tidy_eval"),
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"),
Expand Down Expand Up @@ -103,7 +106,7 @@ tar_terra_vect <- function(name,
library = library,
format = format,
repository = repository,
iteration = iteration,
iteration = "list", #only "list" works for now
error = error,
memory = memory,
garbage_collection = garbage_collection,
Expand Down
3 changes: 3 additions & 0 deletions R/tar_terra_tiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#' @inheritParams targets::tar_target
#' @author Eric Scott
#'
#' @note The `iteration` argument is unavailable because it is hard-coded to
#' `"list"`, the only option that works currently.
#'
#' @return a list of two targets: an upstream target that creates a list of
#' extents and a downstream pattern that maps over these extents to create a
#' list of SpatRaster objects.
Expand Down
25 changes: 4 additions & 21 deletions man/tar_stars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 4 additions & 20 deletions man/tar_terra_rast.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 4 additions & 20 deletions man/tar_terra_sprc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/tar_terra_tiles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 3 additions & 20 deletions man/tar_terra_vect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/test-tar-stars.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,25 @@ targets::tar_test("tar_stars(mdim=TRUE, ncdf=TRUE) works", {
expect_s3_class(x, "stars")
expect_snapshot(x)
})

targets::tar_test("tar_stars() works with dynamic branching", {
targets::tar_script({
list(
geotargets::tar_stars(
test_stars,
stars::read_stars(system.file("tif", "olinda_dem_utm25s.tif", package = "stars"))
),
targets::tar_target(
to_add,
c(1,2)
),
geotargets::tar_stars(
test_stars_plus,
test_stars + to_add,
pattern = map(to_add)
)
)
})
targets::tar_make()
expect_length(targets::tar_read(test_stars_plus), 2)
})
Loading

0 comments on commit ea1f9fe

Please sign in to comment.