Skip to content

Commit f6c32ab

Browse files
authored
Merge pull request #150 from SpatialPlanning/devel
Fix errors
2 parents 9eb14a2 + 9de6303 commit f6c32ab

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

R/splnr_get_MPAs.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#' # Assuming 'dat_PUs' is an existing sf object of planning units in your package.
6060
#'
6161
#' # Example: Get MPAs for Australia and intersect with planning units.
62-
#' dat_mpas <- splnr_get_MPAs(PlanUnits = dat_PUs, Countries = "Australia")
62+
#' dat_mpas <- splnr_get_MPAs(PlanUnits = dat_PUs, Countries = "Australia", force = TRUE)
6363
#'
6464
#' # Example: Get MPAs for multiple countries with specific status and categories.
6565
#' dat_mpas_specific <- splnr_get_MPAs(
@@ -114,11 +114,14 @@ splnr_get_MPAs <- function(PlanUnits,
114114
# TODO Add a check for wdpar package
115115

116116

117-
# Set a chromote timeout option to prevent issues with web scraping for WDPA data.
117+
# Set chromote timeout option to prevent issues with web scraping for WDPA data.
118118
options(chromote.timeout = 120)
119119

120120
# Fetch WDPA data for the specified countries and then process it.
121-
wdpa_data <- Countries %>%
121+
# Note: Chromote may produce benign "Unhandled promise error: Browser.close" messages
122+
# that can be safely ignored (see wdpar documentation and
123+
# https://github.com/rstudio/chromote/pull/111)
124+
wdpa_data <- suppressWarnings(Countries %>%
122125
# Use purrr::map to fetch WDPA data for each country in the 'Countries' vector.
123126
# 'wait = TRUE' ensures sequential downloads, and 'download_dir' specifies where to cache the data.
124127
purrr::map(wdpar::wdpa_fetch,
@@ -127,8 +130,8 @@ splnr_get_MPAs <- function(PlanUnits,
127130
...) %>%
128131
# Bind all fetched data frames into a single data frame.
129132
dplyr::bind_rows() %>%
130-
# Filter for marine protected areas only (where MARINE attribute is greater than 0).
131-
dplyr::filter(.data$MARINE > 0) %>%
133+
# Filter for marine and coastal protected areas only
134+
dplyr::filter(.data$REALM %in% c("Coastal", "Marine")) %>%
132135
# Filter by the specified IUCN Protected Area Management Categories.
133136
dplyr::filter(.data$IUCN_CAT %in% Category) %>%
134137
# Filter by the specified Designation Types.
@@ -144,7 +147,7 @@ splnr_get_MPAs <- function(PlanUnits,
144147
# Select only the 'geometry' column, discarding other attributes after dissolving.
145148
dplyr::select("geometry") %>%
146149
# Add a new column 'wdpa' and set its value to 1, indicating it's a WDPA area.
147-
dplyr::mutate(wdpa = 1)
150+
dplyr::mutate(wdpa = 1))
148151

149152
# Intersect the cleaned WDPA data with the provided planning units using spatialgridr::get_data_in_grid.
150153
# This function identifies which planning units overlap with the WDPA areas.

tests/testthat/test-splnr_plotting.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ testthat::test_that("Correct function output", {
135135
})
136136

137137
testthat::test_that("Correct function output", {
138+
# Suppress deprecation warning from ggcorrplot using aes_string()
138139
expect_s3_class(
139-
splnr_plot_corrMat(splnr_get_kappaCorrData(list(soln1, soln2), name_sol = c("soln1", "soln2")),
140-
AxisLabels = c("Solution 1", "Solution 2"))
140+
suppressWarnings(
141+
splnr_plot_corrMat(splnr_get_kappaCorrData(list(soln1, soln2), name_sol = c("soln1", "soln2")),
142+
AxisLabels = c("Solution 1", "Solution 2")),
143+
classes = "lifecycle_warning_deprecated"
144+
)
141145
, "gg"
142146
)
143147
})

0 commit comments

Comments
 (0)