From 2360ad4a78550fb3760ed3747899632cd3f4682a Mon Sep 17 00:00:00 2001 From: Jeffrey Hanson Date: Fri, 1 Sep 2023 10:26:46 +1200 Subject: [PATCH] update read_spp_range_data() to support multiple shps --- DESCRIPTION | 2 +- NEWS.md | 6 ++ R/read_spp_range_data.R | 15 +++ README.md | 6 +- docs/404.html | 2 +- docs/articles/aoh.html | 32 +++---- docs/articles/customization.html | 34 +++---- docs/articles/index.html | 2 +- docs/authors.html | 6 +- docs/index.html | 93 +++++++++---------- docs/news/index.html | 5 +- docs/pkgdown.yml | 2 +- docs/reference/aoh.html | 2 +- docs/reference/calc_spp_frc_data.html | 37 ++++---- docs/reference/create_spp_aoh_data.html | 24 ++--- docs/reference/create_spp_frc_data.html | 24 ++--- docs/reference/create_spp_info_data.html | 14 +-- docs/reference/crosswalk_jung_lvl1_data.html | 2 +- docs/reference/crosswalk_jung_lvl2_data.html | 2 +- docs/reference/crosswalk_jung_plvl1_data.html | 2 +- docs/reference/crosswalk_lumb_cgls_data.html | 2 +- docs/reference/get_global_elevation_data.html | 2 +- .../reference/get_jung_lvl1_habitat_data.html | 2 +- .../reference/get_jung_lvl2_habitat_data.html | 2 +- .../get_jung_plvl1_habitat_data.html | 2 +- .../reference/get_lumb_cgls_habitat_data.html | 2 +- docs/reference/get_spp_habitat_data.html | 2 +- docs/reference/get_spp_summary_data.html | 2 +- docs/reference/get_spp_threat_data.html | 2 +- docs/reference/index.html | 2 +- docs/reference/is_gdal_calc_available.html | 2 +- docs/reference/is_grass_available.html | 2 +- docs/reference/is_iucn_rl_api_available.html | 2 +- docs/reference/is_osgeo4w_available.html | 2 +- .../iucn_habitat_codes_artificial.html | 2 +- .../iucn_habitat_codes_introduced.html | 2 +- docs/reference/iucn_habitat_codes_marine.html | 2 +- docs/reference/iucn_habitat_codes_misc.html | 2 +- .../iucn_habitat_codes_terrestrial.html | 2 +- docs/reference/iucn_habitat_data.html | 2 +- docs/reference/iucn_threat_data.html | 2 +- docs/reference/plot_spp_aoh_data.html | 25 +++-- docs/reference/plot_spp_frc_data.html | 24 ++--- docs/reference/read_spp_range_data.html | 2 +- docs/reference/simulate_spp_data.html | 4 +- docs/reference/st_repair_geometry.html | 2 +- docs/reference/system_gdal_version.html | 4 +- docs/reference/terra_combine.html | 2 +- docs/reference/terra_gdal_calc.html | 6 +- docs/reference/terra_gdal_crop.html | 4 +- docs/reference/terra_gdal_project.html | 4 +- docs/reference/terra_gdal_rasterize.html | 2 +- inst/doc/aoh.html | 89 ++++++++---------- inst/doc/customization.html | 34 +++---- tests/testthat/test_read_spp_range_data.R | 41 ++++++++ 55 files changed, 320 insertions(+), 277 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a3a6ad3b..0d6a16b4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: aoh Type: Package -Version: 0.0.2.6 +Version: 0.0.2.7 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) diff --git a/NEWS.md b/NEWS.md index 53a9fee6..0e32d8f6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# aoh 0.0.2.7 + +- Update `read_spp_range_data()` to that it can import data from a zip + file that contains multiple ESRI Shapefiles (e.g., the 2022-2 IUCN Red List + release for reptile data). + # aoh 0.0.2.6 - Update `create_spp_aoh_data()` and `create_spp_frc_data()` to have a diff --git a/R/read_spp_range_data.R b/R/read_spp_range_data.R index a660eec9..e146b15e 100644 --- a/R/read_spp_range_data.R +++ b/R/read_spp_range_data.R @@ -81,6 +81,21 @@ read_spp_range_data <- function(path, n = NULL) { # import data if (length(shp_path) == 1) { out <- read_sf_n(shp_path, n = n) + } else if (length(shp_path) > 1) { + ## load data + out <- lapply(shp_path, read_sf_n, n = n) + ## get column names for each shapefile + nms <- lapply(out, names) + ## check that all shapefiles have the same column names + assertthat::assert_that( + all(vapply(nms, FUN.VALUE = logical(1), identical, nms[[1]])), + msg = paste0( + "argument to \"path\" contains multiple shapefiles that have", + "different columns names, and so cannot import spatial data" + ) + ) + ## merge datasets together + out <- dplyr::bind_rows(out) } else if (length(gdb_path) == 1) { # nocov start ## inspect geodatabase gdb_dir <- sf::st_layers(gdb_path) diff --git a/README.md b/README.md index c10c8880..201247ca 100644 --- a/README.md +++ b/README.md @@ -345,11 +345,7 @@ map <- strip.text = element_text(color = "white"), strip.background = element_rect(fill = "black", color = "black") ) -``` - - ## |---------|---------|---------|---------|========================================= -``` r # display maps print(map) ``` @@ -366,7 +362,7 @@ produce Area of Habitat data. relevant data using: Hanson JO (2023) aoh: Create Area of Habitat Data. R package version - 0.0.2.6. Available at https://github.com/prioritizr/aoh. + 0.0.2.7. 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 969684b7..b1cf303d 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/articles/aoh.html b/docs/articles/aoh.html index cc144883..5f65302b 100644 --- a/docs/articles/aoh.html +++ b/docs/articles/aoh.html @@ -33,7 +33,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -83,7 +83,7 @@ @@ -83,7 +83,7 @@ diff --git a/docs/authors.html b/docs/authors.html index 6908e0be..023fa197 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -74,12 +74,12 @@

Citation

-

Hanson JO (2023) aoh: Create Area of Habitat Data. R package version 0.0.2.6. Available at https://github.com/prioritizr/aoh.

+

Hanson JO (2023) aoh: Create Area of Habitat Data. R package version 0.0.2.7. Available at https://github.com/prioritizr/aoh.

@Manual{,
   author = {Jeffrey O Hanson},
   title = {aoh: Create Area of Habitat Data},
   year = {2023},
-  note = {R package version 0.0.2.6},
+  note = {R package version 0.0.2.7},
   url = {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/index.html b/docs/index.html index b313c78c..0db6115a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -46,7 +46,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -302,10 +302,9 @@

Usage axis.text = element_text(size = 6), strip.text = element_text(color = "white"), strip.background = element_rect(fill = "black", color = "black") - ) -
## |---------|---------|---------|---------|=========================================                                          
-
-# display maps
+  )
+
+# display maps
 print(map)

@@ -313,48 +312,48 @@

Usage

Citation

Please cite the aoh R package and the underlying datasets used to produce Area of Habitat data.

-
Area of Habitat data are created using a range of different datasets.
-Depending on which datasets are used, please cite the aoh package and
-relevant data using:
-
-  Hanson JO (2023) aoh: Create Area of Habitat Data. R package version
-  0.0.2.6. Available at https://github.com/prioritizr/aoh.
-
-  IUCN [insert year] IUCN Red List of Threatened Species. Version
-  [insert version]. Available at www.iucnredlist.org.
-
-  BirdLife International and Handbook of the Birds of the World
-  ([insert year]) Bird species distribution maps of the world. Version
-  [insert version]. Available at
-  http://datazone.birdlife.org/species/requestdis.
-
-  Jung M, Dahal PR, Butchart SHM, Donald PF, De Lamo X, Lesiv M, Kapos
-  V, Rondinini C, Visconti P (2020). "A global map of terrestrial
-  habitat types." _Scientific Data_, *7*(1), 256.
-  doi:10.1038/s41597-020-00599-8
-  <https://doi.org/10.1038/s41597-020-00599-8>.
-
-  Jung M, Dahal PR, Butchart SHM, Donald PF, De Lamo X, Lesiv M, Kapos
-  V, Rondinini C, and Visconti P (2020b) A global map of terrestrial
-  habitat types (insert version) [Data set]. Zenodo. Available at
-  https://doi.org/10.5281/zenodo.4058819.
-
-  Lumbierres M, Dahal PR, Di Marco M, Butchart SHM, Donald PF,
-  Rondinini C (2021). "Translating habitat class to land cover to map
-  area of habitat of terrestrial vertebrates." _Conservation Biology_,
-  *36*(3), e13851. doi:10.1111/cobi.13851
-  <https://doi.org/10.1111/cobi.13851>.
-
-  Robinson N, Regetz J, Guralnick RP (2014). "EarthEnv-DEM90: A
-  nearly-global, void-free, multi-scale smoothed 90m digital elevation
-  model from fused ASTER and SRTM data." _ISPRS Journal of
-  Photogrammetry and Remote Sensing_, *87*(1), 57-67.
-  doi:10.1016/j.isprsjprs.2013.11.002
-  <https://doi.org/10.1016/j.isprsjprs.2013.11.002>.
-
-To see these entries in BibTeX format, use 'print(<citation>,
-bibtex=TRUE)', 'toBibtex(.)', or set
-'options(citation.bibtex.max=999)'.
+
Area of Habitat data are created using a range of different datasets.
+Depending on which datasets are used, please cite the aoh package and
+relevant data using:
+
+  Hanson JO (2023) aoh: Create Area of Habitat Data. R package version
+  0.0.2.7. Available at https://github.com/prioritizr/aoh.
+
+  IUCN [insert year] IUCN Red List of Threatened Species. Version
+  [insert version]. Available at www.iucnredlist.org.
+
+  BirdLife International and Handbook of the Birds of the World
+  ([insert year]) Bird species distribution maps of the world. Version
+  [insert version]. Available at
+  http://datazone.birdlife.org/species/requestdis.
+
+  Jung M, Dahal PR, Butchart SHM, Donald PF, De Lamo X, Lesiv M, Kapos
+  V, Rondinini C, Visconti P (2020). "A global map of terrestrial
+  habitat types." _Scientific Data_, *7*(1), 256.
+  doi:10.1038/s41597-020-00599-8
+  <https://doi.org/10.1038/s41597-020-00599-8>.
+
+  Jung M, Dahal PR, Butchart SHM, Donald PF, De Lamo X, Lesiv M, Kapos
+  V, Rondinini C, and Visconti P (2020b) A global map of terrestrial
+  habitat types (insert version) [Data set]. Zenodo. Available at
+  https://doi.org/10.5281/zenodo.4058819.
+
+  Lumbierres M, Dahal PR, Di Marco M, Butchart SHM, Donald PF,
+  Rondinini C (2021). "Translating habitat class to land cover to map
+  area of habitat of terrestrial vertebrates." _Conservation Biology_,
+  *36*(3), e13851. doi:10.1111/cobi.13851
+  <https://doi.org/10.1111/cobi.13851>.
+
+  Robinson N, Regetz J, Guralnick RP (2014). "EarthEnv-DEM90: A
+  nearly-global, void-free, multi-scale smoothed 90m digital elevation
+  model from fused ASTER and SRTM data." _ISPRS Journal of
+  Photogrammetry and Remote Sensing_, *87*(1), 57-67.
+  doi:10.1016/j.isprsjprs.2013.11.002
+  <https://doi.org/10.1016/j.isprsjprs.2013.11.002>.
+
+To see these entries in BibTeX format, use 'print(<citation>,
+bibtex=TRUE)', 'toBibtex(.)', or set
+'options(citation.bibtex.max=999)'.
diff --git a/docs/news/index.html b/docs/news/index.html index 3d709b91..b215cc1f 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7
@@ -60,6 +60,9 @@

Changelog

Source: NEWS.md +
+ +
diff --git a/docs/reference/calc_spp_frc_data.html b/docs/reference/calc_spp_frc_data.html index d1d6b5da..e9bd4772 100644 --- a/docs/reference/calc_spp_frc_data.html +++ b/docs/reference/calc_spp_frc_data.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -237,22 +237,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [1.3s] +#> initializing [1.5s] #> #> cleaning species range data -#> cleaning species range data [1.8s] +#> cleaning species range data [5s] #> #> importing species summary data -#> importing species summary data [441ms] +#> importing species summary data [669ms] #> #> importing species habitat data -#> importing species habitat data [313ms] +#> importing species habitat data [370ms] #> #> collating species data -#> collating species data [148ms] +#> collating species data [421ms] #> #> post-processing results -#> post-processing results [12ms] +#> post-processing results [42ms] #> #> finished @@ -264,27 +264,27 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [4ms] +#> initializing [15ms] #> #> importing global elevation data -#> importing global elevation data [8.4s] +#> importing global elevation data [7.6s] #> #> importing global habitat data #> ! argument to "crosswalk_data" is missing the following 2 habitat classification codes: "7.1", "7.2" #> importing global habitat data -#> importing global habitat data [5.1s] +#> importing global habitat data [5.5s] #> #> generating Area of Habitat data -#> processing ■■■■■■■■■ [ 25% | ETA: 11s] -#> processing ■■■■■■■■■■■■■■■■ [ 50% | ETA: 7s] -#> processing ■■■■■■■■■■■■■■■■■■■■■■■ [ 75% | ETA: 5s] -#> processing [21.3s] +#> processing ■■■■■■■■■ [ 25% | ETA: 30s] +#> processing ■■■■■■■■■■■■■■■■ [ 50% | ETA: 20s] +#> processing ■■■■■■■■■■■■■■■■■■■■■■■ [ 75% | ETA: 13s] +#> processing [59.9s] #> #> generating Area of Habitat data -#> generating Area of Habitat data [21.3s] +#> generating Area of Habitat data [60s] #> #> post-processing results -#> post-processing results [14ms] +#> post-processing results [42ms] #> #> finished @@ -296,7 +296,10 @@

Examples

cache_dir = cache_dir ) #> importing global habitat data -#> importing global habitat data [5.5s] +#> importing global habitat data [5.2s] +#> +#> processing ■■■■■■■■■■■■■■■■ [ 50% | ETA: 1s] +#> processing [4.5s] #> # } diff --git a/docs/reference/create_spp_aoh_data.html b/docs/reference/create_spp_aoh_data.html index 827be02b..0448eed1 100644 --- a/docs/reference/create_spp_aoh_data.html +++ b/docs/reference/create_spp_aoh_data.html @@ -22,7 +22,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -408,22 +408,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [318ms] +#> initializing [1.3s] #> #> cleaning species range data -#> cleaning species range data [3s] +#> cleaning species range data [8.3s] #> #> importing species summary data -#> importing species summary data [318ms] +#> importing species summary data [362ms] #> #> importing species habitat data -#> importing species habitat data [310ms] +#> importing species habitat data [344ms] #> #> collating species data -#> collating species data [209ms] +#> collating species data [561ms] #> #> post-processing results -#> post-processing results [12ms] +#> post-processing results [43ms] #> #> finished @@ -436,22 +436,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [4ms] +#> initializing [15ms] #> #> importing global elevation data -#> importing global elevation data [8s] +#> importing global elevation data [7.3s] #> #> importing global habitat data #> ! argument to "crosswalk_data" is missing the following 2 habitat classification codes: "7.1", "7.2" #> importing global habitat data -#> importing global habitat data [5.1s] +#> importing global habitat data [5.3s] #> #> generating Area of Habitat data #> skipping 4 species distributions already processed -#> generating Area of Habitat data [32ms] +#> generating Area of Habitat data [100ms] #> #> post-processing results -#> post-processing results [14ms] +#> post-processing results [44ms] #> #> finished # } diff --git a/docs/reference/create_spp_frc_data.html b/docs/reference/create_spp_frc_data.html index c8468e44..d82dc876 100644 --- a/docs/reference/create_spp_frc_data.html +++ b/docs/reference/create_spp_frc_data.html @@ -26,7 +26,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -445,22 +445,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [325ms] +#> initializing [375ms] #> #> cleaning species range data -#> cleaning species range data [2.9s] +#> cleaning species range data [8.1s] #> #> importing species summary data -#> importing species summary data [315ms] +#> importing species summary data [361ms] #> #> importing species habitat data -#> importing species habitat data [315ms] +#> importing species habitat data [347ms] #> #> collating species data -#> collating species data [203ms] +#> collating species data [564ms] #> #> post-processing results -#> post-processing results [13ms] +#> post-processing results [50ms] #> #> finished @@ -473,22 +473,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [4ms] +#> initializing [15ms] #> #> importing global elevation data -#> importing global elevation data [6.9s] +#> importing global elevation data [7.7s] #> #> importing global habitat data #> ! argument to "crosswalk_data" is missing the following 2 habitat classification codes: "7.1", "7.2" #> importing global habitat data -#> importing global habitat data [5.2s] +#> importing global habitat data [4.9s] #> #> generating Area of Habitat data #> skipping 4 species distributions already processed -#> generating Area of Habitat data [31ms] +#> generating Area of Habitat data [102ms] #> #> post-processing results -#> post-processing results [34ms] +#> post-processing results [109ms] #> #> finished # } diff --git a/docs/reference/create_spp_info_data.html b/docs/reference/create_spp_info_data.html index dc1cbcf5..23f25f7a 100644 --- a/docs/reference/create_spp_info_data.html +++ b/docs/reference/create_spp_info_data.html @@ -22,7 +22,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -482,22 +482,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [318ms] +#> initializing [347ms] #> #> cleaning species range data -#> cleaning species range data [3s] +#> cleaning species range data [8.1s] #> #> importing species summary data -#> importing species summary data [325ms] +#> importing species summary data [366ms] #> #> importing species habitat data -#> importing species habitat data [312ms] +#> importing species habitat data [346ms] #> #> collating species data -#> collating species data [203ms] +#> collating species data [576ms] #> #> post-processing results -#> post-processing results [12ms] +#> post-processing results [44ms] #> #> finished # } diff --git a/docs/reference/crosswalk_jung_lvl1_data.html b/docs/reference/crosswalk_jung_lvl1_data.html index e769e5cb..ef1fe390 100644 --- a/docs/reference/crosswalk_jung_lvl1_data.html +++ b/docs/reference/crosswalk_jung_lvl1_data.html @@ -28,7 +28,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/crosswalk_jung_lvl2_data.html b/docs/reference/crosswalk_jung_lvl2_data.html index ede55025..b1fd3a7c 100644 --- a/docs/reference/crosswalk_jung_lvl2_data.html +++ b/docs/reference/crosswalk_jung_lvl2_data.html @@ -28,7 +28,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/crosswalk_jung_plvl1_data.html b/docs/reference/crosswalk_jung_plvl1_data.html index 5d3dd5aa..4d6967c0 100644 --- a/docs/reference/crosswalk_jung_plvl1_data.html +++ b/docs/reference/crosswalk_jung_plvl1_data.html @@ -24,7 +24,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/crosswalk_lumb_cgls_data.html b/docs/reference/crosswalk_lumb_cgls_data.html index 6677ccc9..127e668a 100644 --- a/docs/reference/crosswalk_lumb_cgls_data.html +++ b/docs/reference/crosswalk_lumb_cgls_data.html @@ -26,7 +26,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_global_elevation_data.html b/docs/reference/get_global_elevation_data.html index 54b10a40..978554f9 100644 --- a/docs/reference/get_global_elevation_data.html +++ b/docs/reference/get_global_elevation_data.html @@ -20,7 +20,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_jung_lvl1_habitat_data.html b/docs/reference/get_jung_lvl1_habitat_data.html index 14e3cd13..7d5fadbd 100644 --- a/docs/reference/get_jung_lvl1_habitat_data.html +++ b/docs/reference/get_jung_lvl1_habitat_data.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_jung_lvl2_habitat_data.html b/docs/reference/get_jung_lvl2_habitat_data.html index 84ac2939..812a66e0 100644 --- a/docs/reference/get_jung_lvl2_habitat_data.html +++ b/docs/reference/get_jung_lvl2_habitat_data.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_jung_plvl1_habitat_data.html b/docs/reference/get_jung_plvl1_habitat_data.html index f8aafce0..4e288652 100644 --- a/docs/reference/get_jung_plvl1_habitat_data.html +++ b/docs/reference/get_jung_plvl1_habitat_data.html @@ -20,7 +20,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_lumb_cgls_habitat_data.html b/docs/reference/get_lumb_cgls_habitat_data.html index 5ceef355..6d0ddaf6 100644 --- a/docs/reference/get_lumb_cgls_habitat_data.html +++ b/docs/reference/get_lumb_cgls_habitat_data.html @@ -23,7 +23,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_spp_habitat_data.html b/docs/reference/get_spp_habitat_data.html index 56ba3251..2572cf52 100644 --- a/docs/reference/get_spp_habitat_data.html +++ b/docs/reference/get_spp_habitat_data.html @@ -20,7 +20,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_spp_summary_data.html b/docs/reference/get_spp_summary_data.html index 29db929a..02a44218 100644 --- a/docs/reference/get_spp_summary_data.html +++ b/docs/reference/get_spp_summary_data.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/get_spp_threat_data.html b/docs/reference/get_spp_threat_data.html index 4bdfc496..b0e72f71 100644 --- a/docs/reference/get_spp_threat_data.html +++ b/docs/reference/get_spp_threat_data.html @@ -20,7 +20,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/index.html b/docs/reference/index.html index 6763a2ed..40ab6d43 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/is_gdal_calc_available.html b/docs/reference/is_gdal_calc_available.html index 9f296723..0be650f0 100644 --- a/docs/reference/is_gdal_calc_available.html +++ b/docs/reference/is_gdal_calc_available.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/is_grass_available.html b/docs/reference/is_grass_available.html index f1d008f7..6c0054dd 100644 --- a/docs/reference/is_grass_available.html +++ b/docs/reference/is_grass_available.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/is_iucn_rl_api_available.html b/docs/reference/is_iucn_rl_api_available.html index 5619144a..08e66735 100644 --- a/docs/reference/is_iucn_rl_api_available.html +++ b/docs/reference/is_iucn_rl_api_available.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/is_osgeo4w_available.html b/docs/reference/is_osgeo4w_available.html index 0d457828..18c6fe91 100644 --- a/docs/reference/is_osgeo4w_available.html +++ b/docs/reference/is_osgeo4w_available.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/iucn_habitat_codes_artificial.html b/docs/reference/iucn_habitat_codes_artificial.html index 4ae8ce39..594015b4 100644 --- a/docs/reference/iucn_habitat_codes_artificial.html +++ b/docs/reference/iucn_habitat_codes_artificial.html @@ -22,7 +22,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/iucn_habitat_codes_introduced.html b/docs/reference/iucn_habitat_codes_introduced.html index 0d77575a..bb6c3578 100644 --- a/docs/reference/iucn_habitat_codes_introduced.html +++ b/docs/reference/iucn_habitat_codes_introduced.html @@ -22,7 +22,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/iucn_habitat_codes_marine.html b/docs/reference/iucn_habitat_codes_marine.html index 4f415813..ece2eabe 100644 --- a/docs/reference/iucn_habitat_codes_marine.html +++ b/docs/reference/iucn_habitat_codes_marine.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/iucn_habitat_codes_misc.html b/docs/reference/iucn_habitat_codes_misc.html index a19af200..96aa4857 100644 --- a/docs/reference/iucn_habitat_codes_misc.html +++ b/docs/reference/iucn_habitat_codes_misc.html @@ -22,7 +22,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/iucn_habitat_codes_terrestrial.html b/docs/reference/iucn_habitat_codes_terrestrial.html index 9131aaab..d4e28f26 100644 --- a/docs/reference/iucn_habitat_codes_terrestrial.html +++ b/docs/reference/iucn_habitat_codes_terrestrial.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/iucn_habitat_data.html b/docs/reference/iucn_habitat_data.html index dad8f4fe..366102cc 100644 --- a/docs/reference/iucn_habitat_data.html +++ b/docs/reference/iucn_habitat_data.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/iucn_threat_data.html b/docs/reference/iucn_threat_data.html index fbe57717..73260bab 100644 --- a/docs/reference/iucn_threat_data.html +++ b/docs/reference/iucn_threat_data.html @@ -21,7 +21,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/plot_spp_aoh_data.html b/docs/reference/plot_spp_aoh_data.html index f9937abe..ec861890 100644 --- a/docs/reference/plot_spp_aoh_data.html +++ b/docs/reference/plot_spp_aoh_data.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -165,22 +165,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [317ms] +#> initializing [365ms] #> #> cleaning species range data -#> cleaning species range data [3.3s] +#> cleaning species range data [9.1s] #> #> importing species summary data -#> importing species summary data [314ms] +#> importing species summary data [378ms] #> #> importing species habitat data -#> importing species habitat data [317ms] +#> importing species habitat data [355ms] #> #> collating species data -#> collating species data [221ms] +#> collating species data [619ms] #> #> post-processing results -#> post-processing results [13ms] +#> post-processing results [43ms] #> #> finished @@ -192,22 +192,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [4ms] +#> initializing [13ms] #> #> importing global elevation data -#> importing global elevation data [8.4s] +#> importing global elevation data [7.3s] #> #> importing global habitat data #> ! argument to "crosswalk_data" is missing the following 2 habitat classification codes: "7.1", "7.2" #> importing global habitat data -#> importing global habitat data [5.2s] +#> importing global habitat data [4.9s] #> #> generating Area of Habitat data #> skipping 4 species distributions already processed -#> generating Area of Habitat data [32ms] +#> generating Area of Habitat data [99ms] #> #> post-processing results -#> post-processing results [15ms] +#> post-processing results [44ms] #> #> finished @@ -269,7 +269,6 @@

Examples

#> The following object is masked from ‘package:terra’: #> #> inset -#> |---------|---------|---------|---------| ========================================= |---------|---------|---------|---------| ========================================= #> Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL. #> Coordinate system already present. Adding new coordinate system, which will #> replace the existing one. diff --git a/docs/reference/plot_spp_frc_data.html b/docs/reference/plot_spp_frc_data.html index 1adc0623..05d3a42c 100644 --- a/docs/reference/plot_spp_frc_data.html +++ b/docs/reference/plot_spp_frc_data.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -167,22 +167,22 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [314ms] +#> initializing [1.3s] #> #> cleaning species range data -#> cleaning species range data [3.3s] +#> cleaning species range data [7.8s] #> #> importing species summary data -#> importing species summary data [309ms] +#> importing species summary data [365ms] #> #> importing species habitat data -#> importing species habitat data [306ms] +#> importing species habitat data [350ms] #> #> collating species data -#> collating species data [224ms] +#> collating species data [544ms] #> #> post-processing results -#> post-processing results [12ms] +#> post-processing results [44ms] #> #> finished @@ -195,10 +195,10 @@

Examples

cache_dir = cache_dir ) #> initializing -#> initializing [4ms] +#> initializing [15ms] #> #> importing global elevation data -#> importing global elevation data [7.2s] +#> importing global elevation data [7.7s] #> #> importing global habitat data #> ! argument to "crosswalk_data" is missing the following 2 habitat classification codes: "7.1", "7.2" @@ -207,10 +207,10 @@

Examples

#> #> generating Area of Habitat data #> skipping 4 species distributions already processed -#> generating Area of Habitat data [32ms] +#> generating Area of Habitat data [133ms] #> #> post-processing results -#> post-processing results [35ms] +#> post-processing results [140ms] #> #> finished @@ -223,7 +223,7 @@

Examples

) #> importing global habitat data #> skipping 4 species distributions already processed -#> importing global habitat data [5.2s] +#> importing global habitat data [4.9s] #> # plot the data to visualize the range maps and fractional coverage data p <- plot_spp_frc_data(spp_frc_data) diff --git a/docs/reference/read_spp_range_data.html b/docs/reference/read_spp_range_data.html index c490ae47..ea33c6b1 100644 --- a/docs/reference/read_spp_range_data.html +++ b/docs/reference/read_spp_range_data.html @@ -19,7 +19,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/simulate_spp_data.html b/docs/reference/simulate_spp_data.html index d6ad4438..ba490da7 100644 --- a/docs/reference/simulate_spp_data.html +++ b/docs/reference/simulate_spp_data.html @@ -19,7 +19,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -253,7 +253,7 @@

Examples

#> importing global elevation data [6.8s] #> #> importing global habitat data -#> importing global habitat data [44.6s] +#> importing global habitat data [2m 57s] #> # preview species range data diff --git a/docs/reference/st_repair_geometry.html b/docs/reference/st_repair_geometry.html index 1a93f343..3985710c 100644 --- a/docs/reference/st_repair_geometry.html +++ b/docs/reference/st_repair_geometry.html @@ -17,7 +17,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/system_gdal_version.html b/docs/reference/system_gdal_version.html index dd5af8af..33ae7158 100644 --- a/docs/reference/system_gdal_version.html +++ b/docs/reference/system_gdal_version.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -83,7 +83,7 @@

Value

Examples

# show version of GDAL installed
 print(system_gdal_version())
-#> [1] "3.6.2"
+#> [1] "3.6.4"
 
 
diff --git a/docs/reference/terra_combine.html b/docs/reference/terra_combine.html index 43c7c557..96923578 100644 --- a/docs/reference/terra_combine.html +++ b/docs/reference/terra_combine.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/docs/reference/terra_gdal_calc.html b/docs/reference/terra_gdal_calc.html index d6eeefac..9b256bea 100644 --- a/docs/reference/terra_gdal_calc.html +++ b/docs/reference/terra_gdal_calc.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -233,7 +233,7 @@

Examples

# run calculation y <- terra_gdal_calc(x, "(X < 20) * 1") -#> System command: gdal_calc.py -X "/tmp/Rtmpp5yNpV/file66597e006ef9.tif" --outfile="/tmp/Rtmpp5yNpV/file6659105c6f6a.tif" --calc="(X < 20) * 1" --type="Float32" --co="NUM_THREADS=1" --co="COMPRESS=LZW" --co="PREDICTOR=1" +#> System command: gdal_calc.py -X "/tmp/Rtmpxl08oL/file40dd3d5cb12a.tif" --outfile="/tmp/Rtmpxl08oL/file40dd3f0eab31.tif" --calc="(X < 20) * 1" --type="Float32" --co="NUM_THREADS=1" --co="COMPRESS=LZW" --co="PREDICTOR=1" # preview result print(y) @@ -242,7 +242,7 @@

Examples

#> resolution : 0.5, 0.5 (x, y) #> extent : -110, -90, 40, 60 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) -#> source : file6659105c6f6a.tif +#> source : file40dd3f0eab31.tif #> name : lyr.1 # } diff --git a/docs/reference/terra_gdal_crop.html b/docs/reference/terra_gdal_crop.html index 341a03bf..f05d30d4 100644 --- a/docs/reference/terra_gdal_crop.html +++ b/docs/reference/terra_gdal_crop.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -184,7 +184,7 @@

Examples

#> resolution : 0.5, 0.5 (x, y) #> extent : -105, -92.5, 41, 58.5 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) -#> source : file665929e75993.tif +#> source : file40dd42015edd.tif #> name : lyr.1 diff --git a/docs/reference/terra_gdal_project.html b/docs/reference/terra_gdal_project.html index 679914d2..24cc1698 100644 --- a/docs/reference/terra_gdal_project.html +++ b/docs/reference/terra_gdal_project.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 @@ -194,7 +194,7 @@

Examples

#> resolution : 19999.99, 20000 (x, y) #> extent : -944881, 935118, 4664377, 7144377 (xmin, xmax, ymin, ymax) #> coord. ref. : +proj=lcc +lat_0=0 +lon_0=-100 +lat_1=48 +lat_2=33 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs -#> source : file6659494ef599.tif +#> source : file40dd73e4f40a.tif #> name : lyr.1 diff --git a/docs/reference/terra_gdal_rasterize.html b/docs/reference/terra_gdal_rasterize.html index dd709a10..17aca3a1 100644 --- a/docs/reference/terra_gdal_rasterize.html +++ b/docs/reference/terra_gdal_rasterize.html @@ -18,7 +18,7 @@ aoh - 0.0.2.6 + 0.0.2.7 diff --git a/inst/doc/aoh.html b/inst/doc/aoh.html index 1deb9d76..3ef52ec0 100644 --- a/inst/doc/aoh.html +++ b/inst/doc/aoh.html @@ -11,7 +11,7 @@ - + Getting started @@ -169,7 +169,7 @@

Getting started

-

2023-08-12

+

2023-09-01

@@ -282,10 +282,10 @@

Tutorial

## # A tibble: 4 × 5 ## id_no binomial seasonal path geometry ## <dbl> <chr> <int> <chr> <POLYGON [m]> -## 1 979 Alytes dickhilleni 1 /tmp/RtmpOURUC… ((-105506.8 4465112, -10… -## 2 59448 Calotriton asper 1 /tmp/RtmpOURUC… ((-238681 5029057, -2377… -## 3 4657 Chioglossa lusitanica 1 /tmp/RtmpOURUC… ((-859201.6 4559278, -85… -## 4 58622 Rana iberica 1 /tmp/RtmpOURUC… ((-849801.9 4614149, -84… +## 1 979 Alytes dickhilleni 1 /tmp/RtmpwerHV… ((-105506.8 4465112, -10… +## 2 59448 Calotriton asper 1 /tmp/RtmpwerHV… ((-238681 5029057, -2377… +## 3 4657 Chioglossa lusitanica 1 /tmp/RtmpwerHV… ((-859201.6 4559278, -85… +## 4 58622 Rana iberica 1 /tmp/RtmpwerHV… ((-849801.9 4614149, -84…

After generating the Area of Habitat data, we can import them.

# import the Area of Habitat data
 ## since the data for each species have a different spatial extent
@@ -339,59 +339,44 @@ 

Tutorial

## max value : 1

We can see that the Area of Habitat data for each species are stored in separate spatial (raster) datasets with different extents. Although this is useful because it drastically reduces the total size of the data for each species, it can make it difficult to work with data for multiple species. To address this, we can use the terra_combine() function to automatically align and combine the spatial data for all species’ distributions into a single spatial dataset.

# combine raster data
-spp_aoh_rasters <- terra_combine(spp_aoh_rasters)
-
## 
-|---------|---------|---------|---------|
-==============
-                                          
-
-|---------|---------|---------|---------|
-==============
-                                          
-
-|---------|---------|---------|---------|
-==============
-                                          
-
-|---------|---------|---------|---------|
-===========================
-                                          
-
# assign identifiers to layer names
-names(spp_aoh_rasters) <- paste0(
-  "AOH_", spp_aoh_data$id_no, "_", spp_aoh_data$seasonal
-)
-
-# preview raster data
-print(spp_aoh_rasters)
+spp_aoh_rasters <- terra_combine(spp_aoh_rasters) + +# assign identifiers to layer names +names(spp_aoh_rasters) <- paste0( + "AOH_", spp_aoh_data$id_no, "_", spp_aoh_data$seasonal +) + +# preview raster data +print(spp_aoh_rasters)
## class       : SpatRaster 
 ## dimensions  : 7024, 12334, 4  (nrow, ncol, nlyr)
 ## resolution  : 100, 100  (x, y)
 ## extent      : -914731, 318669, 4364377, 5066777  (xmin, xmax, ymin, ymax)
 ## coord. ref. : World_Behrmann 
-## sources     : spat_jpkAiJyKMI43SAq_34914.tif  
-##               spat_1AswexlSJ6eIjiH_34914.tif  
-##               spat_5JlrFLL9XBbxyj7_34914.tif  
-##               spat_lzSZSRsivcj0hdL_34914.tif  
+## sources     : spat_aiaeBr1IfYHZ80P_19967.tif  
+##               spat_vFWbt3LWCRLYVrr_19967.tif  
+##               spat_iw3140MXPUBDjLS_19967.tif  
+##               spat_oGaVdEcdHbcY5MZ_19967.tif  
 ## names       : AOH_979_1, AOH_59448_1, AOH_4657_1, AOH_58622_1 
 ## min values  :         0,           0,          0,           0 
 ## max values  :         1,           1,          1,           1

Finally, let’s create some maps to compare the range data with the Area of habitat data. Although we could create these maps manually (e.g., using the ggplot2 R package), we will use a plotting function distributed with the aoh R package for convenience.

-
# create maps
-## N.B. you might need to install the ggmap package to create the maps
-map <-
-  plot_spp_aoh_data(spp_aoh_data, zoom = 6, maptype = "toner-background") +
-  scale_fill_viridis_d() +
-  scale_color_manual(values = c("range" = "red")) +
-  scale_size_manual(values = c("range" = 0.5)) +
-  theme(
-    axis.title = element_blank(),
-    axis.text = element_text(size = 6),
-    strip.text = element_text(color = "white"),
-    strip.background = element_rect(fill = "black", color = "black")
-  )
-
-# display maps
-print(map)
+
# create maps
+## N.B. you might need to install the ggmap package to create the maps
+map <-
+  plot_spp_aoh_data(spp_aoh_data, zoom = 6, maptype = "toner-background") +
+  scale_fill_viridis_d() +
+  scale_color_manual(values = c("range" = "red")) +
+  scale_size_manual(values = c("range" = 0.5)) +
+  theme(
+    axis.title = element_blank(),
+    axis.text = element_text(size = 6),
+    strip.text = element_text(color = "white"),
+    strip.background = element_rect(fill = "black", color = "black")
+  )
+
+# display maps
+print(map)

@@ -405,8 +390,8 @@

Frequently asked questions

Please open the .Renviron file on your computer (e.g., using usethis::edit_r_environ()). Next, please add the following text to the file (replacing the string with the token) and save the file:

IUCN_REDLIST_KEY="your_actual_token_not_this_string"

Please restart your R session. You should now be able to access the IUCN Red List API. To verify this, please try running the following R code and – assuming everything works correctly – you should see the current version of the IUCN Red List:

-
# verify access to IUCN Red List API
-rredlist::rl_version()
+
# verify access to IUCN Red List API
+rredlist::rl_version()

If these instructions did not work, please consult the documentation for the rredlist R package for further details.

  • Where can I find species range data for generating Area of Habitat data?

    Species range data can be obtained from the IUCN Red List (see Spatial Data Download resources). They can also be obtained from other data sources (see the question below for details).

  • diff --git a/inst/doc/customization.html b/inst/doc/customization.html index 0cfb3e8e..1ca88994 100644 --- a/inst/doc/customization.html +++ b/inst/doc/customization.html @@ -11,7 +11,7 @@ - + Customization @@ -169,7 +169,7 @@

    Customization

    -

    2023-08-12

    +

    2023-09-01

    @@ -675,21 +675,21 @@

    Tutorial

    ## 15 1.5|3.5|3.8|4.4|5.5|14.5 1.5|3.5|3.8|4.4|5.5|14.5 32 ## elevation_upper xmin xmax ymin ymax path ## * <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -## 1 830 -896631 -61631 4373077 5070077 /tmp/RtmpOURUC1/932_1.tif -## 2 999 -902631 -60631 4303077 5070077 /tmp/RtmpOURUC1/3032_1.tif -## 3 874 -707631 320369 4305077 5058077 /tmp/RtmpOURUC1/3046_1.tif -## 4 874 -734631 -504631 4658077 5011077 /tmp/RtmpOURUC1/3046_3.tif -## 5 874 -916631 -708631 4520077 5015077 /tmp/RtmpOURUC1/3046_4.tif -## 6 1050 -620631 320369 4304077 5058077 /tmp/RtmpOURUC1/3255_1.tif -## 7 933 -916631 116369 4304077 5044077 /tmp/RtmpOURUC1/4008_1.tif -## 8 942 -916631 266369 4303077 5070077 /tmp/RtmpOURUC1/4785_1.tif -## 9 1058 -910631 65369 4574077 5070077 /tmp/RtmpOURUC1/4973_1.tif -## 10 1018 -565631 -96631 4304077 4587077 /tmp/RtmpOURUC1/5854_1.tif -## 11 1052 -752631 -66631 4374077 5058077 /tmp/RtmpOURUC1/6068_1.tif -## 12 1017 -284631 239369 4373077 4967077 /tmp/RtmpOURUC1/6678_1.tif -## 13 1017 -794631 -396631 4901077 5070077 /tmp/RtmpOURUC1/6678_2.tif -## 14 1017 -617631 -393631 4304077 4447077 /tmp/RtmpOURUC1/6678_3.tif -## 15 1017 -868631 -654631 4404077 4576077 /tmp/RtmpOURUC1/6678_4.tif +## 1 830 -896631 -61631 4373077 5070077 /tmp/RtmpwerHV5/932_1.tif +## 2 999 -902631 -60631 4303077 5070077 /tmp/RtmpwerHV5/3032_1.tif +## 3 874 -707631 320369 4305077 5058077 /tmp/RtmpwerHV5/3046_1.tif +## 4 874 -734631 -504631 4658077 5011077 /tmp/RtmpwerHV5/3046_3.tif +## 5 874 -916631 -708631 4520077 5015077 /tmp/RtmpwerHV5/3046_4.tif +## 6 1050 -620631 320369 4304077 5058077 /tmp/RtmpwerHV5/3255_1.tif +## 7 933 -916631 116369 4304077 5044077 /tmp/RtmpwerHV5/4008_1.tif +## 8 942 -916631 266369 4303077 5070077 /tmp/RtmpwerHV5/4785_1.tif +## 9 1058 -910631 65369 4574077 5070077 /tmp/RtmpwerHV5/4973_1.tif +## 10 1018 -565631 -96631 4304077 4587077 /tmp/RtmpwerHV5/5854_1.tif +## 11 1052 -752631 -66631 4374077 5058077 /tmp/RtmpwerHV5/6068_1.tif +## 12 1017 -284631 239369 4373077 4967077 /tmp/RtmpwerHV5/6678_1.tif +## 13 1017 -794631 -396631 4901077 5070077 /tmp/RtmpwerHV5/6678_2.tif +## 14 1017 -617631 -393631 4304077 4447077 /tmp/RtmpwerHV5/6678_3.tif +## 15 1017 -868631 -654631 4404077 4576077 /tmp/RtmpwerHV5/6678_4.tif ## geometry ## * <MULTIPOLYGON [m]> ## 1 (((-258785.9 4373975, -259388.9 4373961, -259722.7 4374219, -259763.3 437477… diff --git a/tests/testthat/test_read_spp_range_data.R b/tests/testthat/test_read_spp_range_data.R index ff6d4a0c..2ab480a7 100644 --- a/tests/testthat/test_read_spp_range_data.R +++ b/tests/testthat/test_read_spp_range_data.R @@ -15,6 +15,47 @@ test_that("simulated data (shapefile zip format)", { expect_equal(dplyr::last(names(x)), "geometry") }) +test_that("simulated data (shapefile zip format, multiple files)", { + # unzip data + td1 <- tempfile() + dir.create(td1, showWarnings = FALSE, recursive = TRUE) + utils::unzip( + system.file("testdata", "SIMULATED_SPECIES.zip", package = "aoh"), + exdir = td1 + ) + o <- sf::read_sf(dir(td1, pattern = "^.*\\.shp$", full.names = TRUE)) + # create zip with 2 shapefiles + td2 <- tempfile() + dir.create(td2, showWarnings = FALSE, recursive = TRUE) + n <- nrow(o) + m <- median(seq_len(n)) + sf::write_sf( + o[seq(1, m - 1), , drop = FALSE], + paste0(td2, "/SIMULATED_SPECIES1.shp") + ) + sf::write_sf( + o[seq(m, n), , drop = FALSE], + paste0(td2, "/SIMULATED_SPECIES2.shp") + ) + f <- tempfile(fileext = ".zip") + withr::with_dir(td2, { + archive::archive_write_files(archive = f, files = dir(td2), format = "zip") + }) + # create data + x <- suppressWarnings(read_spp_range_data(f)) + # tests + expect_is(x, "sf") + expect_equal(nrow(x), nrow(o)) + expect_equal(x$id_no, o$id_no) + expect_true(sf::st_crs(x) == st_crs(4326)) + expect_true(all(assertthat::has_name(x, iucn_names))) + expect_equal(dplyr::last(names(x)), "geometry") + # clean up + unlink(td1, force = TRUE, recursive = TRUE) + unlink(td2, force = TRUE, recursive = TRUE) + unlink(f, force = TRUE, recursive = TRUE) +}) + test_that("simulated data (shapefile 7z format)", { # skip if needed skip_on_cran()