From 206aaa7eadf45602bb0a8ca91afc892c0e60f522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darius=20A=2E=20G=C3=B6rgen?= Date: Sun, 3 Nov 2024 09:20:59 +0000 Subject: [PATCH] adds normalizePath() calls to spatial utils --- NEWS.md | 2 ++ R/spatial-utils.R | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index 375d93c6..289066bd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ - `get_biodiversity_intactness_index()`, `get_iucn()`, and `get_key_biodiversity_areas()` now use `spds_exists()` to check if input files exist +- `spds_exist()` and `make_footprints()` now use `normalizePath()` allowing better + handling of relative file paths ## Internal diff --git a/R/spatial-utils.R b/R/spatial-utils.R index 7104268c..ff48728d 100644 --- a/R/spatial-utils.R +++ b/R/spatial-utils.R @@ -34,6 +34,7 @@ #' spds_exists <- function(path, oo = character(0), what = c("vector", "raster")) { what <- match.arg(what) + path <- normalizePath(path, mustWork = FALSE) util <- switch(what, vector = "ogrinfo", raster = "gdalinfo" @@ -138,6 +139,7 @@ make_footprints <- function(srcs = NULL, if (inherits(srcs, "character")) { what <- match.arg(what) + srcs <- normalizePath(srcs, mustWork = FALSE) srcs <- switch(what, vector = purrr::map2(srcs, oo, function(src, opt) .vector_footprint(src, opt)), raster = purrr::map2(srcs, oo, function(src, opt) .raster_footprint(src, opt)), @@ -390,7 +392,9 @@ prep_resources <- function(x, avail_resources = NULL, resources = NULL, mode = c what = c("vector", "raster")) { what <- match.arg(what) stopifnot(is.character(source) && length(source) == 1) + source <- normalizePath(source, mustWork = FALSE) stopifnot(is.character(destination) && length(destination) == 1) + destination <- normalizePath(destination, mustWork = FALSE) stopifnot(is.null(opts) || is.character(opts)) if (is.null(opts)) opts <- character(0)