From 0c71e4f7b46ef6585fd1168ca4f0f8130d5e58cb Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Thu, 7 Mar 2024 15:20:09 -0700 Subject: [PATCH 01/30] rename and fix --- R/tar-geotiff.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/tar-geotiff.R b/R/tar-geotiff.R index e425551..0234e1d 100644 --- a/R/tar-geotiff.R +++ b/R/tar-geotiff.R @@ -1,7 +1,7 @@ -tar_geotiff <- function(name, +tar_terra_rast <- function(name, command, pattern = NULL, - tidy_eval = targets::tar_option("tidy_eval"), + 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"), @@ -16,7 +16,7 @@ tar_geotiff <- function(name, cue = targets::tar_option_get("cue")) { name <- targets::tar_deparse_language(substitute(name)) - envir <- tar_option_get("envir") + envir <- targets::tar_option_get("envir") command <- targets::tar_tidy_eval( expr = as.expression(substitute(command)), From db770ad64ba35e8ce3f13c22365cd108724ee68a Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Thu, 7 Mar 2024 16:21:16 -0700 Subject: [PATCH 02/30] rename and separate out format --- R/formats.R | 17 +++++++++++++ R/tar-geotiff.R | 65 ------------------------------------------------- R/tar-terra.R | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 65 deletions(-) create mode 100644 R/formats.R delete mode 100644 R/tar-geotiff.R create mode 100644 R/tar-terra.R diff --git a/R/formats.R b/R/formats.R new file mode 100644 index 0000000..70cfe58 --- /dev/null +++ b/R/formats.R @@ -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() + ) + } + targets::tar_format( + read = function(path) terra::rast(path), + write = write_fun, + marshal = function(object) terra::wrap(object), + unmarshal = function(object) terra::unwrap(object) + ) +} + diff --git a/R/tar-geotiff.R b/R/tar-geotiff.R deleted file mode 100644 index 0234e1d..0000000 --- a/R/tar-geotiff.R +++ /dev/null @@ -1,65 +0,0 @@ -tar_terra_rast <- function(name, - command, - pattern = NULL, - 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"), - 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_geotiff <- targets::tar_format( - read = function(path) terra::rast(path), - write = function(object, path) { - terra::writeRaster( - x = object, - filename = path, - filetype = "GTiff", - overwrite = TRUE - ) - }, - 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_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 - ) -} diff --git a/R/tar-terra.R b/R/tar-terra.R new file mode 100644 index 0000000..795a18c --- /dev/null +++ b/R/tar-terra.R @@ -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(), + 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 + ) +} From 6a6412906cb0debdd7c2ba2ce1a318bd53d2e869 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Thu, 7 Mar 2024 16:21:51 -0700 Subject: [PATCH 03/30] ignore project .Rprofile --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7c794aa..e39b8c4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .httr-oauth .DS_Store .quarto +.Rprofile From b834996388271aee4f840b40b6d2bc81560f17b9 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Thu, 7 Mar 2024 16:29:19 -0700 Subject: [PATCH 04/30] add simple tests --- tests/testthat/test-formats.R | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/testthat/test-formats.R diff --git a/tests/testthat/test-formats.R b/tests/testthat/test-formats.R new file mode 100644 index 0000000..ffc821f --- /dev/null +++ b/tests/testthat/test-formats.R @@ -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.+") +}) From 2e93be80adbe94952c8f283a51f32f17ed2d0217 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Thu, 7 Mar 2024 16:29:33 -0700 Subject: [PATCH 05/30] add author --- DESCRIPTION | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 98c4486..f5432ff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,17 +4,16 @@ Version: 0.0.0.9000 Authors@R: c( person( given = "Nicholas", - last = "Tierney", + family = "Tierney", email = "nicholas.tierney@gmail.com", 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, From 30edf4b19873083fe5d00905171f21ba8c522916 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Thu, 7 Mar 2024 16:46:43 -0700 Subject: [PATCH 06/30] add clunky version of filetype arg --- R/formats.R | 29 +++++++++++++++++++++-------- tests/testthat/test-formats.R | 4 ++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/R/formats.R b/R/formats.R index 70cfe58..15024d0 100644 --- a/R/formats.R +++ b/R/formats.R @@ -1,11 +1,24 @@ -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() - ) +format_terra_rast <- function(filetype = c("GTiff", "netCDF")) { + filetype <- match.arg(filetype) + #TODO There's got to be a better way to do this by just passing the arg to writeRaster, but I can't figure it out + if(filetype == "GTiff") { + write_fun <- function(object, path) { + terra::writeRaster( + x = object, + filename = path, + overwrite = TRUE, + filetype = "GTiff" + ) + } + } else if (filetype == "netCDF") { + write_fun <- function(object, path) { + terra::writeRaster( + x = object, + filename = path, + overwrite = TRUE, + filetype = "netCDF" + ) + } } targets::tar_format( read = function(path) terra::rast(path), diff --git a/tests/testthat/test-formats.R b/tests/testthat/test-formats.R index ffc821f..e090e6e 100644 --- a/tests/testthat/test-formats.R +++ b/tests/testthat/test-formats.R @@ -3,3 +3,7 @@ test_that("formats return output of tar_format()", { expect_type(format_terra_rast(), "character") expect_match(format_terra_rast(), "^format_custom.+") }) + +test_that("changing filetype does something", { + expect_false(format_terra_rast(filetype = "GTiff") == format_terra_rast(filetype = "netCDF")) +}) From 040b996390d61a6d9ccf101d57ec33a7b814267e Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:09:43 -0700 Subject: [PATCH 07/30] save filetype for a different PR --- R/formats.R | 30 ------------------------------ R/tar-terra.R | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 32 deletions(-) delete mode 100644 R/formats.R diff --git a/R/formats.R b/R/formats.R deleted file mode 100644 index 15024d0..0000000 --- a/R/formats.R +++ /dev/null @@ -1,30 +0,0 @@ -format_terra_rast <- function(filetype = c("GTiff", "netCDF")) { - filetype <- match.arg(filetype) - #TODO There's got to be a better way to do this by just passing the arg to writeRaster, but I can't figure it out - if(filetype == "GTiff") { - write_fun <- function(object, path) { - terra::writeRaster( - x = object, - filename = path, - overwrite = TRUE, - filetype = "GTiff" - ) - } - } else if (filetype == "netCDF") { - write_fun <- function(object, path) { - terra::writeRaster( - x = object, - filename = path, - overwrite = TRUE, - filetype = "netCDF" - ) - } - } - targets::tar_format( - read = function(path) terra::rast(path), - write = write_fun, - marshal = function(object) terra::wrap(object), - unmarshal = function(object) terra::unwrap(object) - ) -} - diff --git a/R/tar-terra.R b/R/tar-terra.R index 795a18c..50d1a1a 100644 --- a/R/tar-terra.R +++ b/R/tar-terra.R @@ -5,7 +5,6 @@ tar_terra_rast <- function(name, packages = targets::tar_option_get("packages"), tidy_eval = targets::tar_option_get("tidy_eval"), library = targets::tar_option_get("library"), - format = format_terra_rast(), repository = targets::tar_option_get("repository"), iteration = targets::tar_option_get("iteration"), error = targets::tar_option_get("error"), @@ -32,13 +31,27 @@ tar_terra_rast <- function(name, 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, + format = format_terra_rast_geotiff, repository = repository, iteration = iteration, error = error, From 706526e1455fcd0400987963d861dfbccae66000 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:10:42 -0700 Subject: [PATCH 08/30] rename test --- tests/testthat/test-tar-terra.R | 3 +++ tests/testthat/test-tar_geotiff.R | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/test-tar-terra.R delete mode 100644 tests/testthat/test-tar_geotiff.R diff --git a/tests/testthat/test-tar-terra.R b/tests/testthat/test-tar-terra.R new file mode 100644 index 0000000..8849056 --- /dev/null +++ b/tests/testthat/test-tar-terra.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +}) diff --git a/tests/testthat/test-tar_geotiff.R b/tests/testthat/test-tar_geotiff.R deleted file mode 100644 index 4cf6dca..0000000 --- a/tests/testthat/test-tar_geotiff.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("tar_geotiff works", { - expect_equal(2 * 2, 4) -}) From f2beefc38f1147fda35134d31eb5a2ce5b1c7dc3 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:29:18 -0700 Subject: [PATCH 09/30] remove @import lines from package doc --- NAMESPACE | 1 + R/geotargets-package.R | 3 --- man/geotargets-package.Rd | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 man/geotargets-package.Rd diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..20ba6e8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,3 @@ # Generated by roxygen2: do not edit by hand +export(tar_terra_rast) diff --git a/R/geotargets-package.R b/R/geotargets-package.R index 97c07e1..a65cf64 100644 --- a/R/geotargets-package.R +++ b/R/geotargets-package.R @@ -2,8 +2,5 @@ "_PACKAGE" ## usethis namespace: start -#' @import rlang -#' @importFrom glue glue -#' @importFrom lifecycle deprecated ## usethis namespace: end NULL diff --git a/man/geotargets-package.Rd b/man/geotargets-package.Rd new file mode 100644 index 0000000..a720a19 --- /dev/null +++ b/man/geotargets-package.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/geotargets-package.R +\docType{package} +\name{geotargets-package} +\alias{geotargets} +\alias{geotargets-package} +\title{geotargets: Targets extensions for geospatial} +\description{ +Provides extensions for various geospatial file formats, including shapefiles, rasters, and more. See the vignettes for worked examples and demonstrations and explanations of how to use the various package extensions +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/njtierney/geotargets} + \item Report bugs at \url{https://github.com/njtierney/geotargets/issues} +} + +} +\author{ +\strong{Maintainer}: Nicholas Tierney \email{nicholas.tierney@gmail.com} (\href{https://orcid.org/0000-0003-1460-8722}{ORCID}) + +Authors: +\itemize{ + \item Eric Scott (\href{https://orcid.org/0000-0002-7430-7879}{ORCID}) +} + +} +\keyword{internal} From ef4adfda96d9b7823282e6f07e51c4ff3ecc9e9a Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:29:29 -0700 Subject: [PATCH 10/30] remove test --- tests/testthat/test-formats.R | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 tests/testthat/test-formats.R diff --git a/tests/testthat/test-formats.R b/tests/testthat/test-formats.R deleted file mode 100644 index e090e6e..0000000 --- a/tests/testthat/test-formats.R +++ /dev/null @@ -1,9 +0,0 @@ -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.+") -}) - -test_that("changing filetype does something", { - expect_false(format_terra_rast(filetype = "GTiff") == format_terra_rast(filetype = "netCDF")) -}) From a2fa9251681af747194c173339b8cdffce53107f Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:32:35 -0700 Subject: [PATCH 11/30] add license file --- .Rbuildignore | 1 + LICENSE | 2 ++ LICENSE.md | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 LICENSE create mode 100644 LICENSE.md diff --git a/.Rbuildignore b/.Rbuildignore index d0adfca..a7db44d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,4 @@ ^README\.Rmd$ ^\.github$ ^codecov\.yml$ +^LICENSE\.md$ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f791d4b --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2024 +COPYRIGHT HOLDER: geotargets authors diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ec60a1b --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2024 geotargets authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 9d184f8462c0141c1b217e2416cc06f18943488c Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:33:02 -0700 Subject: [PATCH 12/30] fix NOTE --- R/tar-shapefile.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tar-shapefile.R b/R/tar-shapefile.R index 541d83a..6b85ec5 100644 --- a/R/tar-shapefile.R +++ b/R/tar-shapefile.R @@ -51,7 +51,7 @@ tar_shapefile <- function(name, cue = targets::tar_option_get("cue")) { name <- targets::tar_deparse_language(substitute(name)) - envir <- tar_option_get("envir") + envir <- targets::tar_option_get("envir") command <- targets::tar_tidy_eval( expr = as.expression(substitute(command)), From c4b67b879d995f006410c3971f7a03a5b2586e09 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:33:20 -0700 Subject: [PATCH 13/30] add test --- tests/testthat/test-tar-terra.R | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-tar-terra.R b/tests/testthat/test-tar-terra.R index 8849056..f259fe9 100644 --- a/tests/testthat/test-tar-terra.R +++ b/tests/testthat/test-tar-terra.R @@ -1,3 +1,14 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) +# test_that() #Included to make RStudio recognize this file as a test +targets::tar_test("tar_terra_rast() works", { + targets::tar_script({ + list( + geotargets::tar_terra_rast( + "test", + system.file("ex/elev.tif", package="terra") |> terra::rast() + ) + ) + }) + targets::tar_make() + x <- targets::tar_read(test) + expect_s4_class(x, "SpatRaster") }) From de5a7fe7da78382e2629a99d3c0f08d787501562 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:34:25 -0700 Subject: [PATCH 14/30] rename --- R/{tar-terra.R => tar-terra-rast.R} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename R/{tar-terra.R => tar-terra-rast.R} (100%) diff --git a/R/tar-terra.R b/R/tar-terra-rast.R similarity index 100% rename from R/tar-terra.R rename to R/tar-terra-rast.R From 6e181c604f398c7a9011560e6d53a864677e00cc Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:35:38 -0700 Subject: [PATCH 15/30] rename shapefile fun --- R/{tar-shapefile.R => tar-terra-vect.R} | 6 +++--- README.Rmd | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename R/{tar-shapefile.R => tar-terra-vect.R} (95%) diff --git a/R/tar-shapefile.R b/R/tar-terra-vect.R similarity index 95% rename from R/tar-shapefile.R rename to R/tar-terra-vect.R index 6b85ec5..e2e5e8c 100644 --- a/R/tar-shapefile.R +++ b/R/tar-terra-vect.R @@ -1,4 +1,4 @@ -format_shapefile <- targets::tar_format( +format_terra_vect_shapefile <- targets::tar_format( read = function(path) { terra::vect( paste0( @@ -33,7 +33,7 @@ format_shapefile <- targets::tar_format( unmarshal = function(object) terra::unwrap(object) ) -tar_shapefile <- function(name, +tar_terra_vect <- function(name, command, pattern = NULL, tidy_eval = targets::tar_option("tidy_eval"), @@ -70,7 +70,7 @@ tar_shapefile <- function(name, pattern = pattern, packages = packages, library = library, - format = format_shapefile, + format = format_terra_vect_shapefile, repository = repository, iteration = iteration, error = error, diff --git a/README.Rmd b/README.Rmd index f051a1d..5b0eb06 100644 --- a/README.Rmd +++ b/README.Rmd @@ -35,7 +35,7 @@ remotes::install_github("njtierney/geotargets") Currently geotargets provides: -- `tar_geotiff` -- `tar_shapefile` +- `tar_terra_rast` +- `tar_terra_vect` But these are under development. From 45de1f16f7cd7e5959af19b1296027af0b94d10a Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:39:30 -0700 Subject: [PATCH 16/30] add missing args --- R/tar-terra-vect.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/tar-terra-vect.R b/R/tar-terra-vect.R index e2e5e8c..f12e633 100644 --- a/R/tar-terra-vect.R +++ b/R/tar-terra-vect.R @@ -36,7 +36,8 @@ format_terra_vect_shapefile <- targets::tar_format( tar_terra_vect <- function(name, command, pattern = NULL, - tidy_eval = targets::tar_option("tidy_eval"), + packages = targets::tar_option_get("packages"), + 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"), From bc92bbb40399e88e4828b1a03b7485e1675d3c26 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 11 Mar 2024 19:40:39 -0700 Subject: [PATCH 17/30] check() wants complete sentences --- DESCRIPTION | 2 +- man/geotargets-package.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f5432ff..a58f984 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Authors@R: c( Description: Provides extensions for various geospatial file formats, including shapefiles, rasters, and more. See the vignettes for worked examples and demonstrations and explanations of how to use the various - package extensions + package extensions. License: MIT + file LICENSE Encoding: UTF-8 Language: en-GB diff --git a/man/geotargets-package.Rd b/man/geotargets-package.Rd index a720a19..d750641 100644 --- a/man/geotargets-package.Rd +++ b/man/geotargets-package.Rd @@ -6,7 +6,7 @@ \alias{geotargets-package} \title{geotargets: Targets extensions for geospatial} \description{ -Provides extensions for various geospatial file formats, including shapefiles, rasters, and more. See the vignettes for worked examples and demonstrations and explanations of how to use the various package extensions +Provides extensions for various geospatial file formats, including shapefiles, rasters, and more. See the vignettes for worked examples and demonstrations and explanations of how to use the various package extensions. } \seealso{ Useful links: From e350ee5dd4d77c53304151a5b125ecca3c5edce4 Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 15:21:07 +1100 Subject: [PATCH 18/30] added documentation and some examples for tar_terra_rast/vect --- NAMESPACE | 1 + R/tar-terra-rast.R | 24 ++++- R/tar-terra-vect.R | 7 ++ man/tar_terra_rast.Rd | 228 ++++++++++++++++++++++++++++++++++++++++++ man/tar_terra_vect.Rd | 211 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 470 insertions(+), 1 deletion(-) create mode 100644 man/tar_terra_rast.Rd create mode 100644 man/tar_terra_vect.Rd diff --git a/NAMESPACE b/NAMESPACE index bf33163..822d790 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,5 @@ # Generated by roxygen2: do not edit by hand export(tar_terra_rast) +export(tar_terra_vect) importFrom(utils,globalVariables) diff --git a/R/tar-terra-rast.R b/R/tar-terra-rast.R index 50d1a1a..a0a8dc5 100644 --- a/R/tar-terra-rast.R +++ b/R/tar-terra-rast.R @@ -1,9 +1,31 @@ +#' 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( +#' test, +#' system.file("ex/elev.tif", package="terra") |> terra::rast() +#' ) +#' ) +#' }) +#' targets::tar_make() +#' x <- targets::tar_read(test) +#' }) +#' } tar_terra_rast <- function(name, command, pattern = NULL, - packages = targets::tar_option_get("packages"), 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"), diff --git a/R/tar-terra-vect.R b/R/tar-terra-vect.R index f12e633..157bb5a 100644 --- a/R/tar-terra-vect.R +++ b/R/tar-terra-vect.R @@ -33,6 +33,13 @@ format_terra_vect_shapefile <- targets::tar_format( unmarshal = function(object) terra::unwrap(object) ) +#' Targets format for terra vectors +#' +#' Provides targets format for `terra::vect` objects +#' +#' @inheritParams targets::tar_target +#' +#' @export tar_terra_vect <- function(name, command, pattern = NULL, diff --git a/man/tar_terra_rast.Rd b/man/tar_terra_rast.Rd new file mode 100644 index 0000000..2bd8648 --- /dev/null +++ b/man/tar_terra_rast.Rd @@ -0,0 +1,228 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tar-terra-rast.R +\name{tar_terra_rast} +\alias{tar_terra_rast} +\title{Targets format for terra rasters} +\usage{ +tar_terra_rast( + 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") +) +} +\arguments{ +\item{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. Subsequent targets +can refer to this name symbolically to induce a dependency relationship: +e.g. \code{tar_target(downstream_target, f(upstream_target))} is a +target named \code{downstream_target} which depends on a target +\code{upstream_target} and a function \code{f()}. In addition, a target's +name determines its random number generator seed. In this way, +each target runs with a reproducible seed so someone else +running the same pipeline should get the same results, +and no two targets in the same pipeline share the same seed. +(Even dynamic branches have different names and thus different seeds.) +You can recover the seed of a completed target +with \code{tar_meta(your_target, seed)} and run \code{\link[targets:tar_seed_set]{tar_seed_set()}} +on the result to locally recreate the target's initial RNG state.} + +\item{command}{R code to run the target.} + +\item{pattern}{Language to define branching for a target. +For example, in a pipeline with numeric vector targets \code{x} and \code{y}, +\code{tar_target(z, x + y, pattern = map(x, y))} implicitly defines +branches of \code{z} that each compute \code{x[1] + y[1]}, \code{x[2] + y[2]}, +and so on. See the user manual for details.} + +\item{tidy_eval}{Logical, whether to enable tidy evaluation +when interpreting \code{command} and \code{pattern}. If \code{TRUE}, you can use the +"bang-bang" operator \verb{!!} to programmatically insert +the values of global objects.} + +\item{packages}{Character vector of packages to load right before +the target runs or the output data is reloaded for +downstream targets. Use \code{tar_option_set()} to set packages +globally for all subsequent targets you define.} + +\item{library}{Character vector of library paths to try +when loading \code{packages}.} + +\item{repository}{Character of length 1, remote repository for target +storage. Choices: +\itemize{ +\item \code{"local"}: file system of the local machine. +\item \code{"aws"}: Amazon Web Services (AWS) S3 bucket. Can be configured +with a non-AWS S3 bucket using the \code{endpoint} argument of +\code{\link[targets:tar_resources_aws]{tar_resources_aws()}}, but versioning capabilities may be lost +in doing so. +See the cloud storage section of +\url{https://books.ropensci.org/targets/data.html} +for details for instructions. +\item \code{"gcp"}: Google Cloud Platform storage bucket. +See the cloud storage section of +\url{https://books.ropensci.org/targets/data.html} +for details for instructions. +} + +Note: if \code{repository} is not \code{"local"} and \code{format} is \code{"file"} +then the target should create a single output file. +That output file is uploaded to the cloud and tracked for changes +where it exists in the cloud. The local file is deleted after +the target runs.} + +\item{iteration}{Character of length 1, name of the iteration mode +of the target. Choices: +\itemize{ +\item \code{"vector"}: branching happens with \code{vctrs::vec_slice()} and +aggregation happens with \code{vctrs::vec_c()}. +\item \code{"list"}, branching happens with \verb{[[]]} and aggregation happens with +\code{list()}. +\item \code{"group"}: \code{dplyr::group_by()}-like functionality to branch over +subsets of a non-dynamic data frame. +For \code{iteration = "group"}, the target must not by dynamic +(the \code{pattern} argument of \code{\link[targets:tar_target]{tar_target()}} must be left \code{NULL}). +The target's return value must be a data +frame with a special \code{tar_group} column of consecutive integers +from 1 through the number of groups. Each integer designates a group, +and a branch is created for each collection of rows in a group. +See the \code{\link[targets:tar_group]{tar_group()}} function to see how you can +create the special \code{tar_group} column with \code{dplyr::group_by()}. +}} + +\item{error}{Character of length 1, what to do if the target +stops and throws an error. Options: +\itemize{ +\item \code{"stop"}: the whole pipeline stops and throws an error. +\item \code{"continue"}: the whole pipeline keeps going. +\item \code{"abridge"}: any currently running targets keep running, +but no new targets launch after that. +(Visit \url{https://books.ropensci.org/targets/debugging.html} +to learn how to debug targets using saved workspaces.) +\item \code{"null"}: The errored target continues and returns \code{NULL}. +The data hash is deliberately wrong so the target is not +up to date for the next run of the pipeline. +}} + +\item{memory}{Character of length 1, memory strategy. +If \code{"persistent"}, the target stays in memory +until the end of the pipeline (unless \code{storage} is \code{"worker"}, +in which case \code{targets} unloads the value from memory +right after storing it in order to avoid sending +copious data over a network). +If \code{"transient"}, the target gets unloaded +after every new target completes. +Either way, the target gets automatically loaded into memory +whenever another target needs the value. +For cloud-based dynamic files +(e.g. \code{format = "file"} with \code{repository = "aws"}), +this memory strategy applies to the +temporary local copy of the file: +\code{"persistent"} means it remains until the end of the pipeline +and is then deleted, +and \code{"transient"} means it gets deleted as soon as possible. +The former conserves bandwidth, +and the latter conserves local storage.} + +\item{garbage_collection}{Logical, whether to run \code{base::gc()} +just before the target runs.} + +\item{deployment}{Character of length 1. If \code{deployment} is +\code{"main"}, then the target will run on the central controlling R process. +Otherwise, if \code{deployment} is \code{"worker"} and you set up the pipeline +with distributed/parallel computing, then +the target runs on a parallel worker. For more on distributed/parallel +computing in \code{targets}, please visit +\url{https://books.ropensci.org/targets/crew.html}.} + +\item{priority}{Numeric of length 1 between 0 and 1. Controls which +targets get deployed first when multiple competing targets are ready +simultaneously. Targets with priorities closer to 1 get dispatched earlier +(and polled earlier in \code{\link[targets:tar_make_future]{tar_make_future()}}).} + +\item{resources}{Object returned by \code{tar_resources()} +with optional settings for high-performance computing +functionality, alternative data storage formats, +and other optional capabilities of \code{targets}. +See \code{tar_resources()} for details.} + +\item{storage}{Character of length 1, only relevant to +\code{\link[targets:tar_make_clustermq]{tar_make_clustermq()}} and \code{\link[targets:tar_make_future]{tar_make_future()}}. +Must be one of the following values: +\itemize{ +\item \code{"main"}: the target's return value is sent back to the +host machine and saved/uploaded locally. +\item \code{"worker"}: the worker saves/uploads the value. +\item \code{"none"}: almost never recommended. It is only for +niche situations, e.g. the data needs to be loaded +explicitly from another language. If you do use it, +then the return value of the target is totally ignored +when the target ends, but +each downstream target still attempts to load the data file +(except when \code{retrieval = "none"}). + +If you select \code{storage = "none"}, then +the return value of the target's command is ignored, +and the data is not saved automatically. +As with dynamic files (\code{format = "file"}) it is the +responsibility of the user to write to +the data store from inside the target. + +The distinguishing feature of \code{storage = "none"} +(as opposed to \code{format = "file"}) +is that in the general case, +downstream targets will automatically try to load the data +from the data store as a dependency. As a corollary, \code{storage = "none"} +is completely unnecessary if \code{format} is \code{"file"}. +}} + +\item{retrieval}{Character of length 1, only relevant to +\code{\link[targets:tar_make_clustermq]{tar_make_clustermq()}} and \code{\link[targets:tar_make_future]{tar_make_future()}}. +Must be one of the following values: +\itemize{ +\item \code{"main"}: the target's dependencies are loaded on the host machine +and sent to the worker before the target runs. +\item \code{"worker"}: the worker loads the targets dependencies. +\item \code{"none"}: the dependencies are not loaded at all. +This choice is almost never recommended. It is only for +niche situations, e.g. the data needs to be loaded +explicitly from another language. +}} + +\item{cue}{An optional object from \code{tar_cue()} to customize the +rules that decide whether the target is up to date.} +} +\description{ +Provides targets format for \code{terra::rast} +} +\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( + test, + system.file("ex/elev.tif", package="terra") |> terra::rast() + ) + ) + }) + targets::tar_make() +x <- targets::tar_read(test) +}) +} +} diff --git a/man/tar_terra_vect.Rd b/man/tar_terra_vect.Rd new file mode 100644 index 0000000..f2e1835 --- /dev/null +++ b/man/tar_terra_vect.Rd @@ -0,0 +1,211 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tar-terra-vect.R +\name{tar_terra_vect} +\alias{tar_terra_vect} +\title{Targets format for terra vectors} +\usage{ +tar_terra_vect( + name, + command, + pattern = NULL, + packages = targets::tar_option_get("packages"), + 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"), + 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") +) +} +\arguments{ +\item{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. Subsequent targets +can refer to this name symbolically to induce a dependency relationship: +e.g. \code{tar_target(downstream_target, f(upstream_target))} is a +target named \code{downstream_target} which depends on a target +\code{upstream_target} and a function \code{f()}. In addition, a target's +name determines its random number generator seed. In this way, +each target runs with a reproducible seed so someone else +running the same pipeline should get the same results, +and no two targets in the same pipeline share the same seed. +(Even dynamic branches have different names and thus different seeds.) +You can recover the seed of a completed target +with \code{tar_meta(your_target, seed)} and run \code{\link[targets:tar_seed_set]{tar_seed_set()}} +on the result to locally recreate the target's initial RNG state.} + +\item{command}{R code to run the target.} + +\item{pattern}{Language to define branching for a target. +For example, in a pipeline with numeric vector targets \code{x} and \code{y}, +\code{tar_target(z, x + y, pattern = map(x, y))} implicitly defines +branches of \code{z} that each compute \code{x[1] + y[1]}, \code{x[2] + y[2]}, +and so on. See the user manual for details.} + +\item{packages}{Character vector of packages to load right before +the target runs or the output data is reloaded for +downstream targets. Use \code{tar_option_set()} to set packages +globally for all subsequent targets you define.} + +\item{tidy_eval}{Logical, whether to enable tidy evaluation +when interpreting \code{command} and \code{pattern}. If \code{TRUE}, you can use the +"bang-bang" operator \verb{!!} to programmatically insert +the values of global objects.} + +\item{library}{Character vector of library paths to try +when loading \code{packages}.} + +\item{repository}{Character of length 1, remote repository for target +storage. Choices: +\itemize{ +\item \code{"local"}: file system of the local machine. +\item \code{"aws"}: Amazon Web Services (AWS) S3 bucket. Can be configured +with a non-AWS S3 bucket using the \code{endpoint} argument of +\code{\link[targets:tar_resources_aws]{tar_resources_aws()}}, but versioning capabilities may be lost +in doing so. +See the cloud storage section of +\url{https://books.ropensci.org/targets/data.html} +for details for instructions. +\item \code{"gcp"}: Google Cloud Platform storage bucket. +See the cloud storage section of +\url{https://books.ropensci.org/targets/data.html} +for details for instructions. +} + +Note: if \code{repository} is not \code{"local"} and \code{format} is \code{"file"} +then the target should create a single output file. +That output file is uploaded to the cloud and tracked for changes +where it exists in the cloud. The local file is deleted after +the target runs.} + +\item{iteration}{Character of length 1, name of the iteration mode +of the target. Choices: +\itemize{ +\item \code{"vector"}: branching happens with \code{vctrs::vec_slice()} and +aggregation happens with \code{vctrs::vec_c()}. +\item \code{"list"}, branching happens with \verb{[[]]} and aggregation happens with +\code{list()}. +\item \code{"group"}: \code{dplyr::group_by()}-like functionality to branch over +subsets of a non-dynamic data frame. +For \code{iteration = "group"}, the target must not by dynamic +(the \code{pattern} argument of \code{\link[targets:tar_target]{tar_target()}} must be left \code{NULL}). +The target's return value must be a data +frame with a special \code{tar_group} column of consecutive integers +from 1 through the number of groups. Each integer designates a group, +and a branch is created for each collection of rows in a group. +See the \code{\link[targets:tar_group]{tar_group()}} function to see how you can +create the special \code{tar_group} column with \code{dplyr::group_by()}. +}} + +\item{error}{Character of length 1, what to do if the target +stops and throws an error. Options: +\itemize{ +\item \code{"stop"}: the whole pipeline stops and throws an error. +\item \code{"continue"}: the whole pipeline keeps going. +\item \code{"abridge"}: any currently running targets keep running, +but no new targets launch after that. +(Visit \url{https://books.ropensci.org/targets/debugging.html} +to learn how to debug targets using saved workspaces.) +\item \code{"null"}: The errored target continues and returns \code{NULL}. +The data hash is deliberately wrong so the target is not +up to date for the next run of the pipeline. +}} + +\item{memory}{Character of length 1, memory strategy. +If \code{"persistent"}, the target stays in memory +until the end of the pipeline (unless \code{storage} is \code{"worker"}, +in which case \code{targets} unloads the value from memory +right after storing it in order to avoid sending +copious data over a network). +If \code{"transient"}, the target gets unloaded +after every new target completes. +Either way, the target gets automatically loaded into memory +whenever another target needs the value. +For cloud-based dynamic files +(e.g. \code{format = "file"} with \code{repository = "aws"}), +this memory strategy applies to the +temporary local copy of the file: +\code{"persistent"} means it remains until the end of the pipeline +and is then deleted, +and \code{"transient"} means it gets deleted as soon as possible. +The former conserves bandwidth, +and the latter conserves local storage.} + +\item{garbage_collection}{Logical, whether to run \code{base::gc()} +just before the target runs.} + +\item{deployment}{Character of length 1. If \code{deployment} is +\code{"main"}, then the target will run on the central controlling R process. +Otherwise, if \code{deployment} is \code{"worker"} and you set up the pipeline +with distributed/parallel computing, then +the target runs on a parallel worker. For more on distributed/parallel +computing in \code{targets}, please visit +\url{https://books.ropensci.org/targets/crew.html}.} + +\item{priority}{Numeric of length 1 between 0 and 1. Controls which +targets get deployed first when multiple competing targets are ready +simultaneously. Targets with priorities closer to 1 get dispatched earlier +(and polled earlier in \code{\link[targets:tar_make_future]{tar_make_future()}}).} + +\item{resources}{Object returned by \code{tar_resources()} +with optional settings for high-performance computing +functionality, alternative data storage formats, +and other optional capabilities of \code{targets}. +See \code{tar_resources()} for details.} + +\item{storage}{Character of length 1, only relevant to +\code{\link[targets:tar_make_clustermq]{tar_make_clustermq()}} and \code{\link[targets:tar_make_future]{tar_make_future()}}. +Must be one of the following values: +\itemize{ +\item \code{"main"}: the target's return value is sent back to the +host machine and saved/uploaded locally. +\item \code{"worker"}: the worker saves/uploads the value. +\item \code{"none"}: almost never recommended. It is only for +niche situations, e.g. the data needs to be loaded +explicitly from another language. If you do use it, +then the return value of the target is totally ignored +when the target ends, but +each downstream target still attempts to load the data file +(except when \code{retrieval = "none"}). + +If you select \code{storage = "none"}, then +the return value of the target's command is ignored, +and the data is not saved automatically. +As with dynamic files (\code{format = "file"}) it is the +responsibility of the user to write to +the data store from inside the target. + +The distinguishing feature of \code{storage = "none"} +(as opposed to \code{format = "file"}) +is that in the general case, +downstream targets will automatically try to load the data +from the data store as a dependency. As a corollary, \code{storage = "none"} +is completely unnecessary if \code{format} is \code{"file"}. +}} + +\item{retrieval}{Character of length 1, only relevant to +\code{\link[targets:tar_make_clustermq]{tar_make_clustermq()}} and \code{\link[targets:tar_make_future]{tar_make_future()}}. +Must be one of the following values: +\itemize{ +\item \code{"main"}: the target's dependencies are loaded on the host machine +and sent to the worker before the target runs. +\item \code{"worker"}: the worker loads the targets dependencies. +\item \code{"none"}: the dependencies are not loaded at all. +This choice is almost never recommended. It is only for +niche situations, e.g. the data needs to be loaded +explicitly from another language. +}} + +\item{cue}{An optional object from \code{tar_cue()} to customize the +rules that decide whether the target is up to date.} +} +\description{ +Provides targets format for \code{terra::vect} objects +} From 02a8753e9a7341c283841060dad2b6faf264a3c7 Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 15:21:21 +1100 Subject: [PATCH 19/30] depend on R 4.1.0, which comes with base pipe |> --- DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 1eb5ef7..221f974 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,6 +30,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 From f82edd47ababf7b073f388e87d4d5806cc747132 Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 15:56:34 +1100 Subject: [PATCH 20/30] implement shapefile method from @brownag https://github.com/njtierney/geotargets/issues/5 and add him as an author --- DESCRIPTION | 6 ++++ R/tar-terra-vect.R | 84 +++++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 221f974..b8c06fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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("ctb"), + comment = c(ORCID = "0000-0002-4565-533X") ) ) Description: Provides extensions for various geospatial file formats, diff --git a/R/tar-terra-vect.R b/R/tar-terra-vect.R index 157bb5a..9f8bb04 100644 --- a/R/tar-terra-vect.R +++ b/R/tar-terra-vect.R @@ -1,37 +1,37 @@ -format_terra_vect_shapefile <- targets::tar_format( - read = function(path) { - terra::vect( - paste0( - "/vsizip/", - file.path( - path, - replace_dot_zip_with_shp(path) - ) - ) - ) - }, - write = function(object, path) { - terra::writeVector( - x = object, - filename = replace_dot_zip_with_shp(path), - filetype = "ESRI Shapefile", - overwrite = TRUE - ) - zf <- list.files( - pattern = replace_dot_zip( - x = path, - replacement = "" - ) - ) - utils::zip( - zipfile = path, - files = zf - ) - unlink(zf) - }, - marshal = function(object) terra::wrap(object), - unmarshal = function(object) terra::unwrap(object) -) +# format_terra_vect_shapefile <- targets::tar_format( +# read = function(path) { +# terra::vect( +# paste0( +# "/vsizip/", +# file.path( +# path, +# replace_dot_zip_with_shp(path) +# ) +# ) +# ) +# }, +# write = function(object, path) { +# terra::writeVector( +# x = object, +# filename = replace_dot_zip_with_shp(path), +# filetype = "ESRI Shapefile", +# overwrite = TRUE +# ) +# zf <- list.files( +# pattern = replace_dot_zip( +# x = path, +# replacement = "" +# ) +# ) +# utils::zip( +# zipfile = path, +# files = zf +# ) +# unlink(zf) +# }, +# marshal = function(object) terra::wrap(object), +# unmarshal = function(object) terra::unwrap(object) +# ) #' Targets format for terra vectors #' @@ -72,13 +72,27 @@ tar_terra_vect <- function(name, tidy_eval = tidy_eval ) + format_terra_shapefile_zip <- tar_format( + read = function(path) terra::vect(paste0("/vsizip/{", path, "}")), + write = function(object, path) { + terra::writeVector( + x = object, + filename = paste0(path, ".shz"), + filetype = "ESRI Shapefile" + ) + file.rename(paste0(path, ".shz"), path) + }, + 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_vect_shapefile, + format = format_terra_shapefile_zip, repository = repository, iteration = iteration, error = error, From 0eb01c2bc629c0d985920b027c7ce1027fb12e6b Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 15:56:48 +1100 Subject: [PATCH 21/30] Add tests and snapshots --- tests/testthat/_snaps/tar-terra.md | 32 +++++++++++++++++++ tests/testthat/test-tar-terra.R | 50 +++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/_snaps/tar-terra.md diff --git a/tests/testthat/_snaps/tar-terra.md b/tests/testthat/_snaps/tar-terra.md new file mode 100644 index 0000000..02703c2 --- /dev/null +++ b/tests/testthat/_snaps/tar-terra.md @@ -0,0 +1,32 @@ +# tar_terra_rast() works + + Code + x + Output + class : SpatRaster + dimensions : 90, 95, 1 (nrow, ncol, nlyr) + resolution : 0.008333333, 0.008333333 (x, y) + extent : 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax, ymin, ymax) + coord. ref. : lon/lat WGS 84 (EPSG:4326) + source : test_terra_rast + name : elevation + min value : 141 + max value : 547 + +# tar_terra_vect() works + + Code + x + Output + class : SpatVector + geometry : polygons + dimensions : 12, 6 (geometries, attributes) + extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) + source : test_terra_vect} (test_terra_vect) + coord. ref. : lon/lat WGS 84 (EPSG:4326) + names : ID_1 NAME_1 ID_2 NAME_2 AREA POP + type : + values : 1 Diekirch 1 Clervaux 312 18081 + 1 Diekirch 2 Diekirch 218 32543 + 1 Diekirch 3 Redange 259 18664 + diff --git a/tests/testthat/test-tar-terra.R b/tests/testthat/test-tar-terra.R index f259fe9..45898e2 100644 --- a/tests/testthat/test-tar-terra.R +++ b/tests/testthat/test-tar-terra.R @@ -1,14 +1,42 @@ # test_that() #Included to make RStudio recognize this file as a test targets::tar_test("tar_terra_rast() works", { - targets::tar_script({ - list( - geotargets::tar_terra_rast( - "test", - system.file("ex/elev.tif", package="terra") |> terra::rast() - ) - ) - }) - targets::tar_make() - x <- targets::tar_read(test) - expect_s4_class(x, "SpatRaster") + targets::tar_script({ + list( + geotargets::tar_terra_rast( + test_terra_rast, + system.file("ex/elev.tif", package = "terra") |> terra::rast() + ) + ) + }) + targets::tar_make() + x <- targets::tar_read(test_terra_rast) + expect_s4_class(x, "SpatRaster") + expect_snapshot( + x + ) +}) + +targets::tar_test("tar_terra_vect() works", { + targets::tar_script({ + lux_area <- function(projection = "EPSG:4326") { + terra::project( + terra::vect(system.file("ex", "lux.shp", + package = "terra" + )), + projection + ) + } + list( + geotargets::tar_terra_vect( + test_terra_vect, + lux_area() + ) + ) + }) + targets::tar_make() + x <- targets::tar_read(test_terra_vect) + expect_s4_class(x, "SpatVector") + expect_snapshot( + x + ) }) From ac796825194b52f6efc2e7380a286d38e5cb0a7c Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 15:57:09 +1100 Subject: [PATCH 22/30] ctb --> aut --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b8c06fa..ab2f53d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ Authors@R: c( person( given = "Andrew", family = "Brown", - role = c("ctb"), + role = c("aut"), comment = c(ORCID = "0000-0002-4565-533X") ) ) From c07d070ec236be6002e0e699a9584e1b79dedddc Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 16:04:07 +1100 Subject: [PATCH 23/30] update pkg examples --- R/tar-terra-rast.R | 26 +++++++++++++------------- R/tar-terra-vect.R | 23 +++++++++++++++++++++++ man/geotargets-package.Rd | 1 + man/tar_terra_rast.Rd | 24 ++++++++++++------------ man/tar_terra_vect.Rd | 24 ++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 25 deletions(-) diff --git a/R/tar-terra-rast.R b/R/tar-terra-rast.R index a0a8dc5..e8feab0 100644 --- a/R/tar-terra-rast.R +++ b/R/tar-terra-rast.R @@ -7,20 +7,20 @@ #' @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( -#' test, -#' system.file("ex/elev.tif", package="terra") |> terra::rast() -#' ) -#' ) -#' }) +#' 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(test) -#' }) -#' } +#' x <- targets::tar_read(terra_rast_example) +#' }) +#'} tar_terra_rast <- function(name, command, pattern = NULL, diff --git a/R/tar-terra-vect.R b/R/tar-terra-vect.R index 9f8bb04..d625f2c 100644 --- a/R/tar-terra-vect.R +++ b/R/tar-terra-vect.R @@ -40,6 +40,29 @@ #' @inheritParams targets::tar_target #' #' @export +#' @examples +#' if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") { +#' targets::tar_dir({ # tar_dir() runs code from a temporary directory. +#' targets::tar_script({ +#' lux_area <- function(projection = "EPSG:4326") { +#' terra::project( +#' terra::vect(system.file("ex", "lux.shp", +#' package = "terra" +#' )), +#' projection +#' ) +#' } +#' list( +#' geotargets::tar_terra_vect( +#' terra_vect_example, +#' lux_area() +#' ) +#' ) +#' }) +#' targets::tar_make() +#' x <- targets::tar_read(terra_vect_example) +#' }) +#' } tar_terra_vect <- function(name, command, pattern = NULL, diff --git a/man/geotargets-package.Rd b/man/geotargets-package.Rd index 8838438..ff8d4db 100644 --- a/man/geotargets-package.Rd +++ b/man/geotargets-package.Rd @@ -22,6 +22,7 @@ Useful links: Authors: \itemize{ \item Eric Scott (\href{https://orcid.org/0000-0002-7430-7879}{ORCID}) + \item Andrew Brown (\href{https://orcid.org/0000-0002-4565-533X}{ORCID}) } } diff --git a/man/tar_terra_rast.Rd b/man/tar_terra_rast.Rd index 2bd8648..8fa0468 100644 --- a/man/tar_terra_rast.Rd +++ b/man/tar_terra_rast.Rd @@ -211,18 +211,18 @@ Provides targets format for \code{terra::rast} } \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( - test, - system.file("ex/elev.tif", package="terra") |> terra::rast() - ) - ) - }) + 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(test) -}) + x <- targets::tar_read(terra_rast_example) + }) } } diff --git a/man/tar_terra_vect.Rd b/man/tar_terra_vect.Rd index f2e1835..3db638f 100644 --- a/man/tar_terra_vect.Rd +++ b/man/tar_terra_vect.Rd @@ -209,3 +209,27 @@ rules that decide whether the target is up to date.} \description{ Provides targets format for \code{terra::vect} objects } +\examples{ +if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") { + targets::tar_dir({ # tar_dir() runs code from a temporary directory. + targets::tar_script({ + lux_area <- function(projection = "EPSG:4326") { + terra::project( + terra::vect(system.file("ex", "lux.shp", + package = "terra" + )), + projection + ) + } + list( + geotargets::tar_terra_vect( + terra_vect_example, + lux_area() + ) + ) + }) + targets::tar_make() + x <- targets::tar_read(terra_vect_example) + }) +} +} From fe9f45b073a4a1d76466296cb9fb3cff76d24bc2 Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 16:04:23 +1100 Subject: [PATCH 24/30] add _targets etc to gitignore and r build ignore --- .Rbuildignore | 7 +++++++ .gitignore | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index a7db44d..89469e1 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,3 +4,10 @@ ^\.github$ ^codecov\.yml$ ^LICENSE\.md$ + +^_targets$ +^_targets_r$ +^_targets\.R$ +^_targets_packages\.R$ +^_targets\.Rmd$ +^_targets\.yaml$ diff --git a/.gitignore b/.gitignore index e39b8c4..4ade709 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,10 @@ .DS_Store .quarto .Rprofile + +_targets_packages.R +_targets +_targets.R +_targets.Rmd +_targets_r +_targets.yaml From d70717b955052721b7d123d157891315ef48930f Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 16:04:29 +1100 Subject: [PATCH 25/30] tweak README --- README.Rmd | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.Rmd b/README.Rmd index fc30106..40d895c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -39,4 +39,4 @@ Currently geotargets provides: - `tar_terra_rast` - `tar_terra_vect` -But these are under development. +These are under active development. diff --git a/README.md b/README.md index 0946805..7cb1300 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ remotes::install_github("njtierney/geotargets") Currently geotargets provides: -- `tar_geotiff` -- `tar_shapefile` +- `tar_terra_rast` +- `tar_terra_vect` -But these are under development. +These are under active development. From ef13606dfa131846854db115dbc88d126c65af3b Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Mar 2024 16:06:13 +1100 Subject: [PATCH 26/30] namespace targets::tar_format --- R/tar-terra-vect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tar-terra-vect.R b/R/tar-terra-vect.R index d625f2c..eadc681 100644 --- a/R/tar-terra-vect.R +++ b/R/tar-terra-vect.R @@ -95,7 +95,7 @@ tar_terra_vect <- function(name, tidy_eval = tidy_eval ) - format_terra_shapefile_zip <- tar_format( + format_terra_shapefile_zip <- targets::tar_format( read = function(path) terra::vect(paste0("/vsizip/{", path, "}")), write = function(object, path) { terra::writeVector( From 6a37d66930f091e483a36ef1ce454914c2ed5b5d Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Mon, 11 Mar 2024 22:37:08 -0700 Subject: [PATCH 27/30] Add `create_format_terra_raster()` internal method for custom format for `tar_terra_rast()` --- R/tar-terra-rast.R | 81 ++++++++++++++++++++++++++++++++++--------- man/tar_terra_rast.Rd | 60 +++++++++++++------------------- man/tar_terra_vect.Rd | 16 +++------ 3 files changed, 94 insertions(+), 63 deletions(-) diff --git a/R/tar-terra-rast.R b/R/tar-terra-rast.R index e8feab0..27e4cd5 100644 --- a/R/tar-terra-rast.R +++ b/R/tar-terra-rast.R @@ -1,9 +1,17 @@ -#' Targets format for terra rasters +#' Create a terra _SpatRaster_ Target #' -#' Provides targets format for `terra::rast` +#' Creates a target for a terra _SpatRaster_ object. +#' +#' @param name Character of length 1, name of the target. +#' @param command An R expression. See `[targets::tar_target()]` for details +#' @param pattern Language to define branching for a target. See `[targets::tar_target()]` for details. +#' @param filetype character. File format expressed as GDAL driver names passed to `terra::writeRaster()` +#' @param gdal character. GDAL driver specific datasource creation options passed to `terra::writeRaster()` +#' @param ... Additional arguments not yet used #' #' @inheritParams targets::tar_target #' +#' @seealso [targets::tar_target_raw()] #' @export #' @examples #' if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") { @@ -24,6 +32,9 @@ tar_terra_rast <- function(name, command, pattern = NULL, + filetype = NULL, + gdal = NULL, + ..., tidy_eval = targets::tar_option_get("tidy_eval"), packages = targets::tar_option_get("packages"), library = targets::tar_option_get("library"), @@ -38,6 +49,7 @@ tar_terra_rast <- function(name, 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") @@ -47,25 +59,21 @@ tar_terra_rast <- function(name, 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) - ) + # could pull defaults from geotargets package options + if (is.null(filetype)) { + filetype <- "GTiff" + } + + if (is.null(gdal)) { + gdal <- "ENCODING=UTF-8" + } targets::tar_target_raw( name = name, @@ -73,7 +81,7 @@ tar_terra_rast <- function(name, pattern = pattern, packages = packages, library = library, - format = format_terra_rast_geotiff, + format = create_format_terra_raster(filetype = filetype, gdal = gdal, ...), repository = repository, iteration = iteration, error = error, @@ -87,3 +95,44 @@ tar_terra_rast <- function(name, cue = cue ) } + +#' @param filetype File format expressed as GDAL driver names passed to `terra::writeRaster()` +#' @param gdal GDAL driver specific datasource creation options passed to `terra::writeRaster()` +#' @param ... Additional arguments not yet used +#' @noRd +create_format_terra_raster <- function(filetype, gdal, ...) { + + if (!requireNamespace("terra")) { + stop("package 'terra' is required", call. = FALSE) + } + + # get list of drivers available for writing depending on what the user's GDAL supports + drv <- terra::gdal(drivers = TRUE) + drv <- drv[drv$type == "raster" & grepl("write", drv$can), ] + + filetype <- match.arg(filetype, drv$name) + + if (is.null(filetype)) { + filetype <- "GTiff" + } + + .write_terra_raster <- function(object, path) { + terra::writeRaster( + object, + path, + filetype = NULL, + overwrite = TRUE, + gdal = NULL + ) + } + body(.write_terra_raster)[[2]][["filetype"]] <- filetype + body(.write_terra_raster)[[2]][["gdal"]] <- gdal + + targets::tar_format( + read = function(path) terra::rast(path), + write = .write_terra_raster, + marshal = function(object) terra::wrap(object), + unmarshal = function(object) terra::unwrap(object) + ) +} + diff --git a/man/tar_terra_rast.Rd b/man/tar_terra_rast.Rd index 8fa0468..8cc5f9e 100644 --- a/man/tar_terra_rast.Rd +++ b/man/tar_terra_rast.Rd @@ -2,12 +2,15 @@ % Please edit documentation in R/tar-terra-rast.R \name{tar_terra_rast} \alias{tar_terra_rast} -\title{Targets format for terra rasters} +\title{Create a terra \emph{SpatRaster} Target} \usage{ tar_terra_rast( name, command, pattern = NULL, + filetype = NULL, + gdal = NULL, + ..., tidy_eval = targets::tar_option_get("tidy_eval"), packages = targets::tar_option_get("packages"), library = targets::tar_option_get("library"), @@ -25,29 +28,17 @@ tar_terra_rast( ) } \arguments{ -\item{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. Subsequent targets -can refer to this name symbolically to induce a dependency relationship: -e.g. \code{tar_target(downstream_target, f(upstream_target))} is a -target named \code{downstream_target} which depends on a target -\code{upstream_target} and a function \code{f()}. In addition, a target's -name determines its random number generator seed. In this way, -each target runs with a reproducible seed so someone else -running the same pipeline should get the same results, -and no two targets in the same pipeline share the same seed. -(Even dynamic branches have different names and thus different seeds.) -You can recover the seed of a completed target -with \code{tar_meta(your_target, seed)} and run \code{\link[targets:tar_seed_set]{tar_seed_set()}} -on the result to locally recreate the target's initial RNG state.} - -\item{command}{R code to run the target.} - -\item{pattern}{Language to define branching for a target. -For example, in a pipeline with numeric vector targets \code{x} and \code{y}, -\code{tar_target(z, x + y, pattern = map(x, y))} implicitly defines -branches of \code{z} that each compute \code{x[1] + y[1]}, \code{x[2] + y[2]}, -and so on. See the user manual for details.} +\item{name}{Character of length 1, name of the target.} + +\item{command}{An R expression. See \verb{[targets::tar_target()]} for details} + +\item{pattern}{Language to define branching for a target. See \verb{[targets::tar_target()]} for details.} + +\item{filetype}{character. File format expressed as GDAL driver names passed to \code{terra::writeRaster()}} + +\item{gdal}{character. GDAL driver specific datasource creation options passed to \code{terra::writeRaster()}} + +\item{...}{Additional arguments not yet used} \item{tidy_eval}{Logical, whether to enable tidy evaluation when interpreting \code{command} and \code{pattern}. If \code{TRUE}, you can use the @@ -93,10 +84,7 @@ aggregation happens with \code{vctrs::vec_c()}. \item \code{"list"}, branching happens with \verb{[[]]} and aggregation happens with \code{list()}. \item \code{"group"}: \code{dplyr::group_by()}-like functionality to branch over -subsets of a non-dynamic data frame. -For \code{iteration = "group"}, the target must not by dynamic -(the \code{pattern} argument of \code{\link[targets:tar_target]{tar_target()}} must be left \code{NULL}). -The target's return value must be a data +subsets of a data frame. The target's return value must be a data frame with a special \code{tar_group} column of consecutive integers from 1 through the number of groups. Each integer designates a group, and a branch is created for each collection of rows in a group. @@ -141,13 +129,10 @@ and the latter conserves local storage.} \item{garbage_collection}{Logical, whether to run \code{base::gc()} just before the target runs.} -\item{deployment}{Character of length 1. If \code{deployment} is -\code{"main"}, then the target will run on the central controlling R process. -Otherwise, if \code{deployment} is \code{"worker"} and you set up the pipeline -with distributed/parallel computing, then -the target runs on a parallel worker. For more on distributed/parallel -computing in \code{targets}, please visit -\url{https://books.ropensci.org/targets/crew.html}.} +\item{deployment}{Character of length 1, only relevant to +\code{\link[targets:tar_make_clustermq]{tar_make_clustermq()}} and \code{\link[targets:tar_make_future]{tar_make_future()}}. If \code{"worker"}, +the target runs on a parallel worker. If \code{"main"}, +the target runs on the host machine / process managing the pipeline.} \item{priority}{Numeric of length 1 between 0 and 1. Controls which targets get deployed first when multiple competing targets are ready @@ -207,7 +192,7 @@ explicitly from another language. rules that decide whether the target is up to date.} } \description{ -Provides targets format for \code{terra::rast} +Creates a target for a terra \emph{SpatRaster} object. } \examples{ if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") { @@ -226,3 +211,6 @@ if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") { }) } } +\seealso{ +\code{\link[targets:tar_target_raw]{targets::tar_target_raw()}} +} diff --git a/man/tar_terra_vect.Rd b/man/tar_terra_vect.Rd index 3db638f..c87eb2c 100644 --- a/man/tar_terra_vect.Rd +++ b/man/tar_terra_vect.Rd @@ -93,10 +93,7 @@ aggregation happens with \code{vctrs::vec_c()}. \item \code{"list"}, branching happens with \verb{[[]]} and aggregation happens with \code{list()}. \item \code{"group"}: \code{dplyr::group_by()}-like functionality to branch over -subsets of a non-dynamic data frame. -For \code{iteration = "group"}, the target must not by dynamic -(the \code{pattern} argument of \code{\link[targets:tar_target]{tar_target()}} must be left \code{NULL}). -The target's return value must be a data +subsets of a data frame. The target's return value must be a data frame with a special \code{tar_group} column of consecutive integers from 1 through the number of groups. Each integer designates a group, and a branch is created for each collection of rows in a group. @@ -141,13 +138,10 @@ and the latter conserves local storage.} \item{garbage_collection}{Logical, whether to run \code{base::gc()} just before the target runs.} -\item{deployment}{Character of length 1. If \code{deployment} is -\code{"main"}, then the target will run on the central controlling R process. -Otherwise, if \code{deployment} is \code{"worker"} and you set up the pipeline -with distributed/parallel computing, then -the target runs on a parallel worker. For more on distributed/parallel -computing in \code{targets}, please visit -\url{https://books.ropensci.org/targets/crew.html}.} +\item{deployment}{Character of length 1, only relevant to +\code{\link[targets:tar_make_clustermq]{tar_make_clustermq()}} and \code{\link[targets:tar_make_future]{tar_make_future()}}. If \code{"worker"}, +the target runs on a parallel worker. If \code{"main"}, +the target runs on the host machine / process managing the pipeline.} \item{priority}{Numeric of length 1 between 0 and 1. Controls which targets get deployed first when multiple competing targets are ready From 879efcaf3b4aa31471fa3cd1972ee9873d79c8f2 Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Mon, 11 Mar 2024 23:14:52 -0700 Subject: [PATCH 28/30] Update tar_terra_rast.Rd - inherit name, command, pattern from `tar_target()` --- R/tar-terra-rast.R | 3 --- man/tar_terra_rast.Rd | 28 +++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/R/tar-terra-rast.R b/R/tar-terra-rast.R index 27e4cd5..56bb101 100644 --- a/R/tar-terra-rast.R +++ b/R/tar-terra-rast.R @@ -2,9 +2,6 @@ #' #' Creates a target for a terra _SpatRaster_ object. #' -#' @param name Character of length 1, name of the target. -#' @param command An R expression. See `[targets::tar_target()]` for details -#' @param pattern Language to define branching for a target. See `[targets::tar_target()]` for details. #' @param filetype character. File format expressed as GDAL driver names passed to `terra::writeRaster()` #' @param gdal character. GDAL driver specific datasource creation options passed to `terra::writeRaster()` #' @param ... Additional arguments not yet used diff --git a/man/tar_terra_rast.Rd b/man/tar_terra_rast.Rd index 8cc5f9e..5b2d452 100644 --- a/man/tar_terra_rast.Rd +++ b/man/tar_terra_rast.Rd @@ -28,11 +28,29 @@ tar_terra_rast( ) } \arguments{ -\item{name}{Character of length 1, name of the target.} - -\item{command}{An R expression. See \verb{[targets::tar_target()]} for details} - -\item{pattern}{Language to define branching for a target. See \verb{[targets::tar_target()]} for details.} +\item{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. Subsequent targets +can refer to this name symbolically to induce a dependency relationship: +e.g. \code{tar_target(downstream_target, f(upstream_target))} is a +target named \code{downstream_target} which depends on a target +\code{upstream_target} and a function \code{f()}. In addition, a target's +name determines its random number generator seed. In this way, +each target runs with a reproducible seed so someone else +running the same pipeline should get the same results, +and no two targets in the same pipeline share the same seed. +(Even dynamic branches have different names and thus different seeds.) +You can recover the seed of a completed target +with \code{tar_meta(your_target, seed)} and run \code{\link[targets:tar_seed_set]{tar_seed_set()}} +on the result to locally recreate the target's initial RNG state.} + +\item{command}{R code to run the target.} + +\item{pattern}{Language to define branching for a target. +For example, in a pipeline with numeric vector targets \code{x} and \code{y}, +\code{tar_target(z, x + y, pattern = map(x, y))} implicitly defines +branches of \code{z} that each compute \code{x[1] + y[1]}, \code{x[2] + y[2]}, +and so on. See the user manual for details.} \item{filetype}{character. File format expressed as GDAL driver names passed to \code{terra::writeRaster()}} From 41b6550528f040c3aba1a7cc630ad854269aaed1 Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Mon, 11 Mar 2024 23:17:51 -0700 Subject: [PATCH 29/30] Update tar_terra_vect.Rd - revert unrelated changes --- man/tar_terra_vect.Rd | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/man/tar_terra_vect.Rd b/man/tar_terra_vect.Rd index c87eb2c..3db638f 100644 --- a/man/tar_terra_vect.Rd +++ b/man/tar_terra_vect.Rd @@ -93,7 +93,10 @@ aggregation happens with \code{vctrs::vec_c()}. \item \code{"list"}, branching happens with \verb{[[]]} and aggregation happens with \code{list()}. \item \code{"group"}: \code{dplyr::group_by()}-like functionality to branch over -subsets of a data frame. The target's return value must be a data +subsets of a non-dynamic data frame. +For \code{iteration = "group"}, the target must not by dynamic +(the \code{pattern} argument of \code{\link[targets:tar_target]{tar_target()}} must be left \code{NULL}). +The target's return value must be a data frame with a special \code{tar_group} column of consecutive integers from 1 through the number of groups. Each integer designates a group, and a branch is created for each collection of rows in a group. @@ -138,10 +141,13 @@ and the latter conserves local storage.} \item{garbage_collection}{Logical, whether to run \code{base::gc()} just before the target runs.} -\item{deployment}{Character of length 1, only relevant to -\code{\link[targets:tar_make_clustermq]{tar_make_clustermq()}} and \code{\link[targets:tar_make_future]{tar_make_future()}}. If \code{"worker"}, -the target runs on a parallel worker. If \code{"main"}, -the target runs on the host machine / process managing the pipeline.} +\item{deployment}{Character of length 1. If \code{deployment} is +\code{"main"}, then the target will run on the central controlling R process. +Otherwise, if \code{deployment} is \code{"worker"} and you set up the pipeline +with distributed/parallel computing, then +the target runs on a parallel worker. For more on distributed/parallel +computing in \code{targets}, please visit +\url{https://books.ropensci.org/targets/crew.html}.} \item{priority}{Numeric of length 1 between 0 and 1. Controls which targets get deployed first when multiple competing targets are ready From 14e9325c2a905b8444b90703ec33e313d736118a Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Mon, 11 Mar 2024 23:33:26 -0700 Subject: [PATCH 30/30] reorder --- R/tar-terra-rast.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tar-terra-rast.R b/R/tar-terra-rast.R index 56bb101..c42704a 100644 --- a/R/tar-terra-rast.R +++ b/R/tar-terra-rast.R @@ -107,12 +107,12 @@ create_format_terra_raster <- function(filetype, gdal, ...) { drv <- terra::gdal(drivers = TRUE) drv <- drv[drv$type == "raster" & grepl("write", drv$can), ] - filetype <- match.arg(filetype, drv$name) - if (is.null(filetype)) { filetype <- "GTiff" } + filetype <- match.arg(filetype, drv$name) + .write_terra_raster <- function(object, path) { terra::writeRaster( object,