diff --git a/DESCRIPTION b/DESCRIPTION index 1ef7bf3..ecfd91a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,7 @@ Description: Tools for downloading spatial data from 'spatiotemporal' asset catalogs ('STAC') and computing standard spectral indices from raster data. License: Apache License (>= 2) Depends: - R (>= 4.0) + R (>= 4.1) Imports: future.apply, glue, diff --git a/R/get_stac_data.R b/R/get_stac_data.R index 3491fb5..52d2499 100644 --- a/R/get_stac_data.R +++ b/R/get_stac_data.R @@ -87,7 +87,7 @@ #' [landsat_band_mapping]. #' @param sign_function A function that takes the output from `query_function` #' and signs the item URLs, if necessary. -#' @param ... Passed to `item_filter_functiion`. +#' @param ... Passed to `item_filter_function`. #' @param rescale_bands Logical of length 1: If the STAC collection implements #' the `raster` STAC extension, and that extension includes `scale` and `offset` #' values, should this function attempt to automatically rescale the downloaded @@ -203,6 +203,19 @@ get_stac_data <- function(aoi, ) } + if (...length() && any(...names() == "")) { + # mostly because of how we put dots in our argument list in sub-functions; + # if any of `...` are not named, then they're getting written one after + # another to "" in the list, which means some will be missing + # + # so, it's an issue with the other get_*_data functions, but we're enforcing + # it everywhere for purposes of consistency + rlang::abort( + "All arguments to `...` must be named.", + class = "rsi_unnamed_dots" + ) + } + if (sf::st_is_longlat(aoi) && !(is.null(pixel_x_size) || is.null(pixel_y_size)) && all(c(pixel_x_size, pixel_y_size) %in% c(10, 30))) { rlang::warn(c( "The default pixel size arguments are intended for use with projected AOIs, but `aoi` appears to be in geographic coordinates.", @@ -602,7 +615,14 @@ get_sentinel1_imagery <- function(aoi, GDAL_HTTP_MERGE_CONSECUTIVE_RANGES = "YES", GDAL_NUM_THREADS = "ALL_CPUS" )) { - args <- as.list(rlang::call_match(defaults = TRUE))[-1] + args <- mget(names(formals())) + args$`...` <- NULL + if (...length()) { + dot_names <- ...names() + for (i in seq_len(...length())) { + args[[dot_names[[i]]]] <- ...elt(i) + } + } do.call(get_stac_data, args) } @@ -645,7 +665,14 @@ get_sentinel2_imagery <- function(aoi, GDAL_HTTP_MERGE_CONSECUTIVE_RANGES = "YES", GDAL_NUM_THREADS = "ALL_CPUS" )) { - args <- as.list(rlang::call_match(defaults = TRUE))[-1] + args <- mget(names(formals())) + args$`...` <- NULL + if (...length()) { + dot_names <- ...names() + for (i in seq_len(...length())) { + args[[dot_names[[i]]]] <- ...elt(i) + } + } do.call(get_stac_data, args) } @@ -689,7 +716,14 @@ get_landsat_imagery <- function(aoi, GDAL_HTTP_MERGE_CONSECUTIVE_RANGES = "YES", GDAL_NUM_THREADS = "ALL_CPUS" )) { - args <- as.list(rlang::call_match(defaults = TRUE))[-1] + args <- mget(names(formals())) + args$`...` <- NULL + if (...length()) { + dot_names <- ...names() + for (i in seq_len(...length())) { + args[[dot_names[[i]]]] <- ...elt(i) + } + } do.call(get_stac_data, args) } @@ -732,7 +766,14 @@ get_dem <- function(aoi, GDAL_HTTP_MERGE_CONSECUTIVE_RANGES = "YES", GDAL_NUM_THREADS = "ALL_CPUS" )) { - args <- as.list(rlang::call_match(defaults = TRUE))[-1] + args <- mget(names(formals())) + args$`...` <- NULL + if (...length()) { + dot_names <- ...names() + for (i in seq_len(...length())) { + args[[dot_names[[i]]]] <- ...elt(i) + } + } do.call(get_stac_data, args) } diff --git a/man/get_stac_data.Rd b/man/get_stac_data.Rd index 2723f09..2f1e210 100644 --- a/man/get_stac_data.Rd +++ b/man/get_stac_data.Rd @@ -173,7 +173,7 @@ images from.} \link{sentinel1_band_mapping}, \link{sentinel2_band_mapping}, and \link{landsat_band_mapping}.} -\item{...}{Passed to \code{item_filter_functiion}.} +\item{...}{Passed to \code{item_filter_function}.} \item{sign_function}{A function that takes the output from \code{query_function} and signs the item URLs, if necessary.} diff --git a/tests/testthat/test-get_stac_data.R b/tests/testthat/test-get_stac_data.R index 56610fa..6213961 100644 --- a/tests/testthat/test-get_stac_data.R +++ b/tests/testthat/test-get_stac_data.R @@ -186,6 +186,7 @@ test_that("simple merge method works", { }) test_that("warning (but not error) fires if `mask_band` is not NULL with NULL `mask_function`", { + skip_on_cran() aoi <- sf::st_point(c(-74.912131, 44.080410)) aoi <- sf::st_set_crs(sf::st_sfc(aoi), 4326) aoi <- sf::st_buffer(sf::st_transform(aoi, 3857), 1000) @@ -201,3 +202,20 @@ test_that("warning (but not error) fires if `mask_band` is not NULL with NULL `m ) ) }) + +test_that("get_*_data works with mapply() (#17)", { + skip_on_cran() + san_antonio = sf::st_point(c(-98.491142, 29.424349)) + san_antonio = sf::st_sfc(san_antonio, crs = "EPSG:4326") + san_antonio = sf::st_buffer(st_transform(san_antonio, "EPSG:3081"), 1000) + + expect_no_error( + mapply( + get_landsat_imagery, + start_date = c("2023-09-01", "2023-10-01"), + end_date = c("2023-09-30", "2023-10-31"), + output_filename = replicate(2, tempfile(fileext = ".tif")), + MoreArgs = c(aoi = list(san_antonio)) + ) + ) +})