Skip to content

Commit 00f339c

Browse files
authored
Merge pull request #172 from ropensci/gdal-version-check
Fix for CRAN error relating to GDAL version
2 parents eb51e48 + 4264c04 commit 00f339c

15 files changed

+85
-35
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
2424
- {os: ubuntu-latest, r: 'release'}
2525
- {os: ubuntu-latest, r: 'oldrel-1'}
26+
- {os: ubuntu-22.04, r: 'release'} #test with older version of GDAL
2627

2728
env:
2829
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ docs
1616
inst/doc
1717
/doc/
1818
/Meta/
19+
.Renviron

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: geotargets
22
Title: 'targets' Extensions for Geographic Spatial Formats
3-
Version: 0.3.0.9000
3+
Version: 0.3.1
44
Authors@R: c(
55
person(
66
given = "Nicholas",
@@ -37,7 +37,8 @@ Imports:
3737
terra (>= 1.8-10),
3838
withr (>= 3.0.0),
3939
zip,
40-
lifecycle
40+
lifecycle,
41+
gdalraster (>= 2.0.0)
4142
Suggests:
4243
crew (>= 0.9.2),
4344
knitr,
@@ -47,7 +48,6 @@ Suggests:
4748
stars,
4849
testthat (>= 3.0.0),
4950
fs,
50-
gdalraster,
5151
spelling
5252
Config/testthat/edition: 3
5353
URL: https://github.com/ropensci/geotargets, https://docs.ropensci.org/geotargets/

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# geotargets (development version)
1+
# geotargets 0.3.1 (15 May 2025)
2+
3+
* Throws an error if `preserve_metadata = "gdalraster_sozip"` in function `tar_terra_rast()` and if GDAL is less than 3.7. Skips testing this feature when GDAL < 3.7 also. This fixes a bug picked up by the CRAN team.
4+
* Tests also don't report progress bars, as mentioned by CRAN team.
25

36
# geotargets 0.3.0 (16 April 2025)
47

R/tar-terra-rast.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ tar_terra_rast <- function(
113113

114114
if (preserve_metadata == "gdalraster_sozip") {
115115
check_pkg_installed("gdalraster")
116+
check_gdal_sozip()
116117
}
117118

118119
# ensure that user-passed `resources` doesn't include `custom_format`

R/utils.R

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,29 @@ check_pkg_installed <- function(pkg, call = rlang::caller_env()) {
1616
}
1717

1818
gdal_version <- function() {
19-
numeric_version(terra::gdal(lib = "gdal"))
19+
numeric_version(gdalraster::gdal_version()[4])
2020
}
2121

22+
gdal_version_lt <- function(version) {
23+
gdal_version() < numeric_version(version)
24+
}
25+
26+
27+
check_gdal_sozip <- function(call = rlang::caller_env()) {
28+
gdal_cannot_sozip <- gdal_version_lt("3.7.0")
29+
if (gdal_cannot_sozip) {
30+
cli::cli_abort(
31+
message = c(
32+
"Must have {.pkg GDAL} version {.val 3.7} or greater",
33+
"i" = "To use {.arg preserve_metadata = 'gdalraster_sozip'}",
34+
"x" = "We see {.pkg GDAL} version: {.val {gdal_version()}}"
35+
),
36+
call = call
37+
)
38+
}
39+
}
40+
41+
2242
check_gdal_shz <- function(min_version = "3.1", call = rlang::caller_env()) {
2343
if (gdal_version() < numeric_version(min_version)) {
2444
cli::cli_abort(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# GDAL version checked checked
2+
3+
Code
4+
check_gdal_sozip()
5+
Condition
6+
Error:
7+
! Must have GDAL version "3.7" or greater
8+
i To use `preserve_metadata = 'gdalraster_sozip'`
9+
x We see GDAL version: 3.0.0
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test_that("GDAL version checked checked", {
2+
local_mocked_bindings(
3+
gdal_version = function(...) numeric_version("3.0.0")
4+
)
5+
expect_snapshot(
6+
error = TRUE,
7+
check_gdal_sozip()
8+
)
9+
})

tests/testthat/test-geotargets-option.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ targets::tar_test("geotargets_options_get() retrieves options in correct priorit
1111
)
1212
)
1313
})
14-
targets::tar_make()
14+
targets::tar_make(reporter = "silent")
1515
expect_identical(
1616
geotargets::geotargets_option_get("gdal.raster.driver"),
1717
"GIF"

tests/testthat/test-tar-stars.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ targets::tar_test("tar_stars() works", {
1414
)
1515
))
1616
})
17-
targets::tar_make()
17+
targets::tar_make(reporter = "silent")
1818
x <- targets::tar_read(test_stars)
1919
expect_s3_class(x, "stars")
2020
expect_snapshot(
@@ -34,7 +34,7 @@ targets::tar_test("tar_stars_proxy() works", {
3434
)
3535
))
3636
})
37-
targets::tar_make()
37+
targets::tar_make(reporter = "silent")
3838
x <- targets::tar_read(test_stars_proxy)
3939
expect_s3_class(x, "stars_proxy")
4040
expect_snapshot(
@@ -62,7 +62,7 @@ targets::tar_test("tar_stars(mdim=TRUE) works", {
6262
))
6363
})
6464

65-
targets::tar_make()
65+
targets::tar_make(reporter = "silent")
6666
x <- targets::tar_read(test_stars_mdim)
6767
expect_s3_class(x, "stars")
6868
expect_snapshot(x)
@@ -91,7 +91,7 @@ targets::tar_test("tar_stars(mdim=TRUE, ncdf=TRUE) works", {
9191
))
9292
})
9393

94-
targets::tar_make()
94+
targets::tar_make(reporter = "silent")
9595
# warnings related to no CRS
9696
suppressWarnings({
9797
x <- targets::tar_read(test_stars_mdim_ncdf)
@@ -120,6 +120,6 @@ targets::tar_test("tar_stars() works with dynamic branching", {
120120
)
121121
)
122122
})
123-
targets::tar_make()
123+
targets::tar_make(reporter = "silent")
124124
expect_length(targets::tar_read(test_stars_plus), 2)
125125
})

0 commit comments

Comments
 (0)