diff --git a/.Rbuildignore b/.Rbuildignore index e930762a..dd9b68f1 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -51,6 +51,7 @@ frc-data-birds-part-5.Rout frc-data-birds-part-6.Rout frc-data-mammals.Rout frc-data-reptiles.Rout +iucn-species-list.csv ^aoh.R$ ^customization.R$ codecov.yml diff --git a/.gitignore b/.gitignore index 93889de6..f57f4d8c 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ frc-data-birds-part-5.Rout frc-data-birds-part-6.Rout frc-data-mammals.Rout frc-data-reptiles.Rout +iucn-species-list.csv # system files .directory diff --git a/DESCRIPTION b/DESCRIPTION index 0f5e88b1..7cb50019 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: aoh Type: Package -Version: 0.0.2.13 +Version: 0.0.2.14 Title: Create Area of Habitat Data Description: Create Area of Habitat data to characterize species distributions. Data are produced following procedures outlined by Brooks et al. (2019) @@ -73,7 +73,7 @@ SystemRequirements: GDAL (>= 3.0.2) (optional), PROJ (>= 7.2.0) (optional) URL: https://prioritizr.github.io/aoh/, https://github.com/prioritizr/aoh BugReports: https://github.com/prioritizr/aoh/issues VignetteBuilder: knitr -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Collate: 'internal.R' 'calc_spp_frc_data.R' diff --git a/Makefile b/Makefile index 25f3c31b..37bc639a 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,9 @@ prep_lumbierres_habitat_data: inst/scripts/lumbierres-habitat-data.R R CMD BATCH --no-restore --no-save inst/scripts/lumbierres-habitat-data.R # process aoh data -aoh_global_data: aoh_amphibians aoh_mammals aoh_reptiles aoh_birds +aoh_global_data: aoh_amphibians aoh_mammals aoh_reptiles aoh_birds aoh_mammals + +aoh_mammals: aoh_mammals_land aoh_mammals_land_freshwater aoh_mammals_land_marine aoh_amphibians: R CMD BATCH --no-restore --no-save '--args amphibians' inst/scripts/aoh-data.R aoh-data-amphibians.Rout @@ -51,8 +53,14 @@ aoh_birds: R CMD BATCH --no-restore --no-save '--args birds-part-5' inst/scripts/aoh-data.R aoh-data-birds-part-5.Rout R CMD BATCH --no-restore --no-save '--args birds-part-6' inst/scripts/aoh-data.R aoh-data-birds-part-6.Rout -aoh_mammals: - R CMD BATCH --no-restore --no-save '--args mammals' inst/scripts/aoh-data.R aoh-data-mammals.Rout +aoh_mammals_land: + R CMD BATCH --no-restore --no-save '--args mammals-land' inst/scripts/aoh-data.R aoh-data-mammals-land.Rout + +aoh_mammals_land_freshwater: + R CMD BATCH --no-restore --no-save '--args mammals-land-freshwater' inst/scripts/aoh-data.R aoh-data-mammals-land-freshwater.Rout + +aoh_mammals_land_marine: + R CMD BATCH --no-restore --no-save '--args mammals-land-marine' inst/scripts/aoh-data.R aoh-data-mammals-land-marine.Rout aoh_reptiles: R CMD BATCH --no-restore --no-save '--args reptiles' inst/scripts/aoh-data.R aoh-data-reptiles.Rout @@ -132,4 +140,4 @@ purl_vigns: R --slave -e "lapply(dir('vignettes', '^.*\\\\.Rmd$$'), function(x) knitr::purl(file.path('vignettes', x), gsub('.Rmd', '.R', x, fixed = TRUE)))" rm -f Rplots.pdf -.PHONY: initc vigns clean data docs readme site test check checkwb build purl_vigns install man spellcheck examples prep_habitat_data prep_elevation_data aoh_reptiles aoh_mammals aoh_birds aoh_amphibians aoh_global_data frc_reptiles frc_mammals frc_birds frc_amphibians frc_global_data +.PHONY: initc vigns clean data docs readme site test check checkwb build purl_vigns install man spellcheck examples prep_habitat_data prep_elevation_data aoh_reptiles aoh_mammals aoh_mammals_land aoh_mammals_land_freshwater aoh_mammals_land_marine aoh_birds aoh_amphibians aoh_global_data frc_reptiles frc_mammals frc_birds frc_amphibians frc_global_data diff --git a/NEWS.md b/NEWS.md index a12af42e..6e6b7280 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,14 @@ +# aoh 0.0.2.14 + +- Update `create_spp_info_data()` to make data cleaning functionality more + robust for the BirdLife species' range dataset. +- Update built-in helper script for processing area of habitat data to + include (i) mammal speices with terrestrial and freshwater distributions and + (ii) mammal speices with terrestrial and marine distributions + (see `inst/scripts/aoh-data.R`) +- New built-in helper script to download all species identifiers from the + IUCN Red List (see `inst/scripts/iucn-species-list.R`) + # aoh 0.0.2.13 - Update `read_spp_range_data()` and `create_spp_info_data()` to fix diff --git a/R/clean_spp_range_data.R b/R/clean_spp_range_data.R index 47c46507..ac8316fa 100644 --- a/R/clean_spp_range_data.R +++ b/R/clean_spp_range_data.R @@ -402,9 +402,11 @@ clean_spp_range_data <- function(x, # step 6: convert MULTISURFACE to MULTIPOLYGON x <- sf::st_set_precision(x, geometry_precision) idx <- which(vapply(sf::st_geometry(x), inherits, logical(1), "MULTISURFACE")) - if (length(idx) > 0) { # nocov start + # nocov start + if (length(idx) > 0) { g <- sf::st_geometry(x) - g2 <- lapply(g[idx], sf::st_cast, "MULTIPOLYGON") + g2 <- g[idx] + g2 <- lapply(g2, sf::st_cast, "MULTIPOLYGON") g2 <- lapply(g2, sf::st_buffer, 0) g2 <- lapply(g2, sf::st_make_valid) for (i in seq_along(idx)) { @@ -412,9 +414,14 @@ clean_spp_range_data <- function(x, } x <- sf::st_set_geometry(x, g) rm(g, g2) - } # nocov end + } + # nocov end + + # force construction of object, this seems to be needed for some reason + # that I do not understand, otherwise st_collection_extract() throws + # an error + x <- x[seq_len(nrow(x)), , drop = FALSE] x <- suppressWarnings(sf::st_collection_extract(x, "POLYGON")) - invisible(gc()) # step 7: fix any potential geometry issues x <- st_repair_geometry(x, geometry_precision) @@ -422,8 +429,11 @@ clean_spp_range_data <- function(x, # step 8: wrap geometries to dateline x <- sf::st_set_precision(x, geometry_precision) - x <- suppressWarnings(sf::st_wrap_dateline(x, - options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180")) + x <- suppressWarnings( + sf::st_wrap_dateline( + x, + options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180") + ) ) invisible(gc()) diff --git a/R/st_repair_geometry.R b/R/st_repair_geometry.R index eb7e48f0..4613fcff 100644 --- a/R/st_repair_geometry.R +++ b/R/st_repair_geometry.R @@ -153,7 +153,7 @@ st_repair_geometry <- function(x, geometry_precision = 1e5) { requireNamespace("prepr", quietly = TRUE), msg = paste( "the \"prepr\" package needs to be installed, use: \n", - "remotes::install_github(\"dickoa/prepr\")" + "remotes::install_github(\"prioritizr/prepr\")" ) ) ### find geometries to repair diff --git a/README.md b/README.md index 41ac4f19..d88c4d36 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ produce Area of Habitat data. relevant data using: Hanson JO (2024) aoh: Create Area of Habitat Data. R package version - 0.0.2.12. Available at https://github.com/prioritizr/aoh. + 0.0.2.14. Available at https://github.com/prioritizr/aoh. IUCN [insert year] IUCN Red List of Threatened Species. Version [insert version]. Available at www.iucnredlist.org. diff --git a/docs/404.html b/docs/404.html index f440a131..c7bb1e6a 100644 --- a/docs/404.html +++ b/docs/404.html @@ -6,7 +6,7 @@