diff --git a/DESCRIPTION b/DESCRIPTION index cdb0f83..903abed 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,7 @@ Imports: stats, utils, raster, - rgdal + terra Authors@R: c( person("Samuel", "Bosch", email = "mail@samuelbosch.com", role = c("aut")), person("Lennert", "Tyberghein", email = "lennert.tyberghein@vliz.be", role = c("ctb")), @@ -35,5 +35,5 @@ Suggests: rmarkdown, httr, httr2 -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.3 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 3747841..7120296 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,7 +19,6 @@ export(lonlatproj) export(pearson_correlation_matrix) export(plot_correlation) export(sdm_to_bo) -import(rgdal) import(stats) import(utils) importFrom(raster,raster) diff --git a/R/load.R b/R/load.R index e3b8140..56c639d 100644 --- a/R/load.R +++ b/R/load.R @@ -109,7 +109,7 @@ load_layers <- function(layercodes, equalarea = FALSE, rasterstack = TRUE, datad if(max(counts) != NROW(layercodes)) { warning("Layers from different eras (current, future, paleo) are being loaded together") } - if(!rgdal::GDALis3ormore()){ + if(gdal_is_lower_than_3()){ warning("GDAL is lower than version 3. Consider updating GDAL to avoid errors.") } datadir <- get_datadir(datadir) @@ -180,3 +180,13 @@ lonlatproj <- sp::CRS("+proj=longlat +datum=WGS84 +no_defs") #' using load_layers with equal_area = TRUE #' @export equalareaproj <- sp::CRS("+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") + +#' Is gdal v3 or more? +#' @noRd +gdal_is_lower_than_3 <- function(){ + vgdal <- terra::gdal() + vgdal <- strsplit(vgdal, ".", fixed = TRUE)[[1]][1] + vgdal <- as.numeric(vgdal) + is_less_than_3 <- vgdal < 3 + is_less_than_3 +} \ No newline at end of file diff --git a/R/sdmpredictors.R b/R/sdmpredictors.R index 4f11e39..1e405ed 100644 --- a/R/sdmpredictors.R +++ b/R/sdmpredictors.R @@ -33,5 +33,5 @@ #' @name sdmpredictors #' #' @importFrom raster raster stack -#' @import stats utils rgdal +#' @import stats utils NULL \ No newline at end of file diff --git a/tests/testthat/test_load.R b/tests/testthat/test_load.R index 0be5eae..fb3e076 100644 --- a/tests/testthat/test_load.R +++ b/tests/testthat/test_load.R @@ -1,5 +1,5 @@ library(sdmpredictors) -library(raster) +suppressWarnings({library(raster)}) test_dir <- file.path(tempdir(), "sdmpredictors") options(sdmpredictors_datadir = test_dir) @@ -58,7 +58,9 @@ test_that("load_layer equal area layer works", { }) test_that("load_layer works with different datadir options", { normalize <- function(p) { - normalizePath(paste0(p,"/"), winslash = "/", mustWork = TRUE) + suppressWarnings({ + normalizePath(paste0(p,"/"), winslash = "/", mustWork = TRUE) + }) } rpath <- function(rs) { path <- gsub("/vsizip/", "", dirname(raster::raster(rs,1)@file@name), fixed = TRUE) @@ -174,7 +176,7 @@ test_that("GDAL virtual file system works to read zipped raster files", { rs <- raster::raster(url) expect_equal(class(rs)[1], "RasterLayer") - expect_true(rgdal::GDALis3ormore()) + expect_false(gdal_is_lower_than_3()) })