Skip to content

Commit 3a0594b

Browse files
authored
Merge pull request #453 from mapme-initiative/develop
check system requirements
2 parents f04a22f + 33da4d4 commit 3a0594b

12 files changed

+39
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ rsconnect/
5353
## Add any custom .gitignore items below
5454

5555
# folder with development related stuff
56-
develop/
56+
develop
5757

5858
# renv related files and folders
5959
renv.lock

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: mapme.biodiversity
22
Title: Efficient Monitoring of Global Biodiversity Portfolios
3-
Version: 0.9.4.9006
3+
Version: 0.9.4.9007
44
Authors@R: c(person(given = "Darius A.",
55
family = "G\u00F6rgen",
66
role = "aut",

NEWS.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mapme.biodiversity 0.9.4.9006
1+
# mapme.biodiversity 0.9.4.9007
22

33
## General
44

@@ -10,12 +10,14 @@
1010
## Internal
1111

1212
- internal function `.has_internet()` now delegates to `curl::has_internet()`
13+
- added function `.check_system_requirements()` that checks on package load if system requirements (GDAL and PROJ versions) are met and warns if not
1314

1415
## Bug fixes
1516

1617
- internal function `.fetch_resource()` now correctly takes into account the resources that could not be retrieved and reports them ([433](https://github.com/mapme-initiative/mapme.biodiversity/issues/433))
1718
- fixed messages from the `check_namespace()` function
18-
- fixed the way `normalizePath()` is ised so it works correctly on Windows ([446](https://github.com/mapme-initiative/mapme.biodiversity/issues/446))
19+
- fixed the way `normalizePath()` is used so it works correctly on Windows ([446](https://github.com/mapme-initiative/mapme.biodiversity/issues/446))
20+
- fixed `calc_treecover_area()` to correctly handle the full tree cover (100%) ([451](https://github.com/mapme-initiative/mapme.biodiversity/issues/451))
1921

2022
# mapme.biodiversity 0.9.4
2123

R/calc_treecover_area.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ calc_treecover_area <- function(years = 2000:2024,
155155
data[data[["patches"]] %in% keep_patches, ]
156156
}
157157

158-
.sum_gfw <- function(data, what = "coverage_area", max_year = 2023) {
158+
.sum_gfw <- function(data, what, max_year) {
159159
# calculate loss area by year
160160
df <- data.frame(years = 2000:max_year, var = 0)
161161
names(df)[2] <- what
@@ -243,7 +243,8 @@ calc_treecover_area <- function(years = 2000:2024,
243243
# binarize the treecover layer based on min_cover argument
244244
rcl<- matrix(c(NA, NA, 0,
245245
0, cover, 0,
246-
cover, 100, 1), ncol = 3, byrow = TRUE)
246+
cover, 100.001, 1), ncol = 3, byrow = TRUE)
247+
# need value > 100 to include 100 with 'right = FALSE'
247248
binary_treecover <- terra::classify(treecover,
248249
rcl = rcl,
249250
right = FALSE, others = NA)

R/calc_treecover_area_and_emissions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ calc_treecover_area_and_emissions <- function(years = 2000:2024,
102102
data <- .prep_gfw_data(data, min_size)
103103
losses <- .sum_gfw(data, "coverage_area", max_year)
104104
names(losses)[2] <- "loss"
105-
emissions <- .sum_gfw(data, "emissions")
105+
emissions <- .sum_gfw(data, "emissions", max_year)
106106

107107
org_coverage <- sum(data[["coverage_area"]])
108108

R/register.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
log_dir = NULL,
1515
verbose = TRUE
1616
)
17+
.check_system_requirements()
1718
invisible()
1819
}
1920

@@ -312,3 +313,17 @@ available_indicators <- function(indicators = NULL) {
312313
.clear_resources <- function() {
313314
.pkgenv$avail_resources <- list()
314315
}
316+
317+
.check_system_requirements <- function() {
318+
chk <- mapply(.compare_sf_version, c("GDAL", "PROJ"), c("3.7.0", "4.8.0"))
319+
invisible()
320+
}
321+
322+
.compare_sf_version <- function(lib, target) {
323+
installed_version <- sf::sf_extSoftVersion()[[lib]]
324+
if (utils::compareVersion(installed_version, target) < 0) {
325+
msg <- sprintf("%s system library version (%s) < %s", lib, installed_version, target)
326+
warning(msg, call. = FALSE)
327+
}
328+
}
329+

tests/testthat/_snaps/calc_treecover_area.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
Code
44
result$value
55
Output
6-
[1] 2050.641 2050.348 2048.659 2017.076 2008.575 2004.666
6+
[1] 2057.330 2056.816 2055.127 2021.265 2011.870 2007.594
77

tests/testthat/_snaps/calc_treecover_area_and_emissions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
Code
44
result$value
55
Output
6-
[1] 0.0000 2050.6413 120.3610 2050.3477 619.3609 2048.6594
7-
[7] 11905.1140 2017.0757 3297.2784 2008.5752 1590.3710 2004.6661
6+
[1] 0.0000 2057.3295 212.5268 2056.8158 619.3609 2055.1275
7+
[7] 12932.7655 2021.2651 3676.1357 2011.8703 1731.4164 2007.5943
88

tests/testthat/_snaps/calc_treecoverloss_emissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
Code
44
result$value
55
Output
6-
[1] 0.0000 120.3610 619.3609 11905.1140 3297.2784 1590.3710
6+
[1] 0.0000 212.5268 619.3609 12932.7655 3676.1357 1731.4164
77

tests/testthat/test-calc_carbon.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
test_that("calc_irr_carbon works", {
2+
# CRAN checks fail on some platforms, not reproducible
3+
skip_on_cran()
24
x <- read_sf(system.file("extdata", "shell_beach_protected_area_41057_B.gpkg",
35
package = "mapme.biodiversity"
46
))
@@ -32,6 +34,8 @@ test_that("calc_irr_carbon works", {
3234

3335

3436
test_that("calc_vul_carbon works", {
37+
# CRAN checks fail on some platforms, not reproducible
38+
skip_on_cran()
3539
x <- read_sf(system.file("extdata", "shell_beach_protected_area_41057_B.gpkg",
3640
package = "mapme.biodiversity"
3741
))
@@ -64,6 +68,8 @@ test_that("calc_vul_carbon works", {
6468
})
6569

6670
test_that("calc_man_carbon works", {
71+
# CRAN checks fail on some platforms, not reproducible
72+
skip_on_cran()
6773
x <- read_sf(system.file("extdata", "shell_beach_protected_area_41057_B.gpkg",
6874
package = "mapme.biodiversity"
6975
))

0 commit comments

Comments
 (0)