Skip to content

Commit

Permalink
Merge pull request #387 from mapme-initiative/fix-manual-files
Browse files Browse the repository at this point in the history
uses spds_exists for resources that are specified manually
  • Loading branch information
goergen95 authored Oct 28, 2024
2 parents 94ee47f + 079abc9 commit 169fe28
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 2 additions & 5 deletions R/get_biodiversity_intactness_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion R/get_iucn.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

Expand Down
2 changes: 1 addition & 1 deletion R/get_key_biodiversity_areas.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-get_biodiversity_intactness_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 169fe28

Please sign in to comment.