Skip to content

Commit

Permalink
delete redundant option getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Aariq committed Mar 26, 2024
1 parent 04bea6c commit 1c5abb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
19 changes: 4 additions & 15 deletions R/tar-terra-rast.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ tar_terra_rast <- function(name,
filetype <- filetype %||% "GTiff"
gdal <- gdal %||% "ENCODING=UTF-8"

#check that filetype option is available
drv <- get_gdal_available_driver_list("raster")
filetype <- rlang::arg_match0(filetype, drv$name)

check_pkg_installed("terra")

name <- targets::tar_deparse_language(substitute(name))
Expand All @@ -69,14 +73,6 @@ tar_terra_rast <- function(name,
tidy_eval = tidy_eval
)

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")
filetype <- rlang::arg_match0(filetype, drv$name)

gdal <- gdal %||% geotargets_option_get("gdal.raster.creation_options")

targets::tar_target_raw(
name = name,
command = command,
Expand Down Expand Up @@ -106,13 +102,6 @@ create_format_terra_raster <- function(filetype, gdal, ...) {

check_pkg_installed("terra")

drv <- get_gdal_available_driver_list("raster")

filetype <- filetype %||% geotargets_option_get("gdal.raster.driver")
filetype <- rlang::arg_match0(filetype, drv$name)

gdal <- gdal %||% geotargets_option_get("gdal.raster.creation_options")

.write_terra_raster <- eval(substitute(function(object, path) {
terra::writeRaster(
object,
Expand Down
18 changes: 4 additions & 14 deletions R/tar-terra-vect.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ tar_terra_vect <- function(name,
filetype <- filetype %||% "GeoJSON"
gdal <- gdal %||% "ENCODING=UTF-8"

#Check that filetype is available
drv <- get_gdal_available_driver_list("vector")
filetype <- rlang::arg_match0(filetype, drv$name)

check_pkg_installed("terra")

name <- targets::tar_deparse_language(substitute(name))
Expand All @@ -77,14 +81,6 @@ tar_terra_vect <- function(name,
tidy_eval = tidy_eval
)

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")
filetype <- rlang::arg_match0(filetype, drv$name)

gdal <- gdal %||% geotargets_option_get("gdal.vector.creation_options")

format <- ifelse(
test = filetype == "ESRI Shapefile",
#special handling of ESRI shapefiles because the output is a dir of multiple files.
Expand Down Expand Up @@ -124,12 +120,6 @@ create_format_terra_vect <- function(filetype, options, ...) {

check_pkg_installed("terra")

drv <- get_gdal_available_driver_list("vector")

filetype <- filetype %||% "GeoJSON"

filetype <- match.arg(filetype, drv$name)

.write_terra_vector <- eval(substitute(function(object, path) {
terra::writeVector(
object,
Expand Down

0 comments on commit 1c5abb8

Please sign in to comment.