diff --git a/R/tar-terra-rast.R b/R/tar-terra-rast.R index 089cf2e..ffd01b1 100644 --- a/R/tar-terra-rast.R +++ b/R/tar-terra-rast.R @@ -67,9 +67,7 @@ tar_terra_rast <- function(name, tidy_eval = tidy_eval ) - # get list of drivers available for writing depending on what the user's GDAL supports - drv <- terra::gdal(drivers = TRUE) - drv <- drv[drv$type == "raster" & grepl("write", drv$can), ] + drv <- get_gdal_available_driver_list("raster") # if not specified by user, pull the corresponding geotargets option filetype <- filetype %||% geotargets_option_get("gdal.raster.driver") @@ -106,9 +104,7 @@ create_format_terra_raster <- function(filetype, gdal, ...) { check_pkg_installed("terra") - # get list of drivers available for writing depending on what the user's GDAL supports - drv <- terra::gdal(drivers = TRUE) - drv <- drv[drv$type == "raster" & grepl("write", drv$can), ] + drv <- get_gdal_available_driver_list("raster") filetype <- filetype %||% geotargets_option_get("gdal.raster.driver") filetype <- rlang::arg_match0(filetype, drv$name) diff --git a/R/tar-terra-vect.R b/R/tar-terra-vect.R index 8eddcc9..b3441c7 100644 --- a/R/tar-terra-vect.R +++ b/R/tar-terra-vect.R @@ -75,9 +75,7 @@ tar_terra_vect <- function(name, tidy_eval = tidy_eval ) - # get list of drivers available for writing depending on what the user's GDAL supports - drv <- terra::gdal(drivers = TRUE) - drv <- drv[drv$type == "vector" & grepl("write", drv$can), ] + drv <- get_gdal_available_driver_list("vector") # if not specified by user, pull the corresponding geotargets option filetype <- filetype %||% geotargets_option_get("gdal.vector.driver") @@ -124,9 +122,7 @@ create_format_terra_vect <- function(filetype, options, ...) { check_pkg_installed("terra") - # get list of drivers available for writing depending on what the user's GDAL supports - drv <- terra::gdal(drivers = TRUE) - drv <- drv[drv$type == "vector" & grepl("write", drv$can), ] + drv <- get_gdal_available_driver_list("vector") if (is.null(filetype)) { filetype <- "GeoJSON" diff --git a/R/utils.R b/R/utils.R index 8494296..9d21a94 100644 --- a/R/utils.R +++ b/R/utils.R @@ -13,3 +13,10 @@ check_pkg_installed <- function(pkg, call = rlang::caller_env()) { ) } } + +get_gdal_available_driver_list <- function(driver_type){ + # get list of drivers available for writing depending on what the user's GDAL supports + drv <- terra::gdal(drivers = TRUE) + drv <- drv[drv$type == driver_type & grepl("write", drv$can), ] + drv +}