From 079abc9d8f30a58953ed613b3822b3ead6896bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darius=20A=2E=20G=C3=B6rgen?= Date: Mon, 28 Oct 2024 14:32:06 +0000 Subject: [PATCH] uses spds_exists for resources that are specified manually --- NEWS.md | 5 +++++ R/get_biodiversity_intactness_index.R | 7 ++----- R/get_iucn.R | 2 +- R/get_key_biodiversity_areas.R | 2 +- tests/testthat/test-get_biodiversity_intactness_index.R | 6 +++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3222bb34..e6144e26 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # mapme.biodiversity (development version) +## General + +- `get_biodiversity_intactness_index()`, `get_iucn()`, and `get_key_biodiversity_areas()` + now use `spds_exists()` to check if input files exist + # mapme.biodiversity 0.9.3 ## Bug fixes diff --git a/R/get_biodiversity_intactness_index.R b/R/get_biodiversity_intactness_index.R index 928eedf8..dc16410b 100644 --- a/R/get_biodiversity_intactness_index.R +++ b/R/get_biodiversity_intactness_index.R @@ -20,11 +20,8 @@ #' @include register.R #' @export get_biodiversity_intactness_index <- function(path = NULL) { - if (is.null(path) || !file.exists(path)) { - stop("Expecting path to point towards an existing file.") - } - if (!endsWith(path, ".asc")) { - stop("Unexpected file extension: path must point towards a '.asc' file.") + if (is.null(path) || !endsWith(path, ".asc") || !spds_exists(path, what = "raster")) { + stop("Expecting path to point towards an existing '.asc' file.") } function( diff --git a/R/get_iucn.R b/R/get_iucn.R index 2cb70a1b..bb060f33 100644 --- a/R/get_iucn.R +++ b/R/get_iucn.R @@ -21,7 +21,7 @@ #' @include register.R #' @export get_iucn <- function(paths = NULL) { - if (is.null(paths) || !all(file.exists(paths)) || !all(endsWith(paths, ".tif"))) { + if (is.null(paths) || !all(endsWith(paths, ".tif")) || !all(sapply(paths, spds_exists, what = "raster"))) { stop("Expecting paths to point towards existing GTiff files.") } diff --git a/R/get_key_biodiversity_areas.R b/R/get_key_biodiversity_areas.R index f50b1513..e492f5e1 100644 --- a/R/get_key_biodiversity_areas.R +++ b/R/get_key_biodiversity_areas.R @@ -25,7 +25,7 @@ #' @export get_key_biodiversity_areas <- function(path = NULL) { - if(is.null(path) || !file.exists(path) || file.info(path) [["isdir"]]) { + if(is.null(path) || !spds_exists(path, what = "raster")) { stop("Expecting path to point towards an existing file.") } diff --git a/tests/testthat/test-get_biodiversity_intactness_index.R b/tests/testthat/test-get_biodiversity_intactness_index.R index ae4ec8a6..6e3ef6b4 100644 --- a/tests/testthat/test-get_biodiversity_intactness_index.R +++ b/tests/testthat/test-get_biodiversity_intactness_index.R @@ -5,15 +5,15 @@ test_that("get_biodiversity_intactness_index works", { expect_error( get_biodiversity_intactness_index(NULL), - "Expecting path to point towards an existing file." + "Expecting path to point towards an existing '.asc' file." ) expect_error( get_biodiversity_intactness_index(), - "Expecting path to point towards an existing file." + "Expecting path to point towards an existing '.asc' file." ) expect_error( get_biodiversity_intactness_index(sample_path), - "Unexpected file extension: path must point towards a '.asc' file." + "Expecting path to point towards an existing '.asc' file." ) x <- read_sf(sample_path)