diff --git a/R/get.R b/R/get.R index 9cc043d8..d2839df6 100644 --- a/R/get.R +++ b/R/get.R @@ -95,6 +95,10 @@ #' @param download_only Boolean. If `TRUE`, then the function only returns the #' path where the matched file is stored, instead of reading it. `FALSE` by #' default. +#' @param remove_gpkg Boolean. If `TRUE`, the `.gpkg` files created by +#' `oe_vectortranslate` are deleted after reading them. This might be useful +#' when using these functions in a new R package or an external server. +#' Default value is `FALSE`. #' @param ... (Named) arguments that will be passed to [`sf::st_read()`], like #' `query`, `wkt_filter` or `stringsAsFactors`. Check the introductory #' vignette to understand how to create your own (SQL-like) queries. @@ -220,6 +224,7 @@ oe_get = function( download_only = FALSE, skip_vectortranslate = FALSE, never_skip_vectortranslate = FALSE, + remove_gpkg = FALSE, quiet = FALSE ) { @@ -263,6 +268,7 @@ oe_get = function( never_skip_vectortranslate = never_skip_vectortranslate, boundary = boundary, boundary_type = boundary_type, + remove_gpkg = remove_gpkg, quiet = quiet, ... ) diff --git a/R/read.R b/R/read.R index 1f12b98e..3208bc25 100644 --- a/R/read.R +++ b/R/read.R @@ -91,6 +91,7 @@ oe_read = function( never_skip_vectortranslate = FALSE, boundary = NULL, boundary_type = c("spat", "clipsrc"), + remove_gpkg = FALSE, quiet = FALSE ) { @@ -329,6 +330,12 @@ oe_read = function( stop("An error occurred during the vectortranslate process", call. = FALSE) } + # If remove_gpkg is TRUE, then remove the gpkg file created by oe_vectortranslate + if (isTRUE(remove_gpkg)) { + oe_message("Removing the .gpkg created by oe_vectortranslate.", quiet = quiet) + on.exit(unlink(gpkg_file_path)) + } + # Read the translated file with sf::st_read. Moreover, starting from sf 1.0.2, # sf::st_read raises a warning message when both layer and query arguments are # set (while it raises a warning in sf < 1.0.2 when there are multiple layers diff --git a/R/utils.R b/R/utils.R index 8fc87fcd..b4309552 100644 --- a/R/utils.R +++ b/R/utils.R @@ -47,6 +47,7 @@ oe_download_directory = function() { # Print a message if quiet argument is FALSE. I defined this function since the # same pattern is repeated several times in the package. oe_message <- function(..., quiet) { + # NB: quiet argument must always be named if (isFALSE(quiet)) { message(...) } diff --git a/man/oe_get.Rd b/man/oe_get.Rd index 6871bc36..79b40c5c 100644 --- a/man/oe_get.Rd +++ b/man/oe_get.Rd @@ -24,6 +24,7 @@ oe_get( download_only = FALSE, skip_vectortranslate = FALSE, never_skip_vectortranslate = FALSE, + remove_gpkg = FALSE, quiet = FALSE ) } @@ -135,6 +136,11 @@ passed its own \code{.ini} file or vectortranslate options (since, in those case, it's too difficult to determine if an existing \code{.gpkg} file was generated following the same options.)} +\item{remove_gpkg}{Boolean. If \code{TRUE}, the \code{.gpkg} files created by +\code{oe_vectortranslate} are deleted after reading them. This might be useful +when using these functions in a new R package or an external server. +Default value is \code{FALSE}.} + \item{quiet}{Boolean. If \code{FALSE}, the function prints informative messages. Starting from \code{sf} version \href{https://r-spatial.github.io/sf/news/index.html#version-0-9-6-2020-09-13}{0.9.6}, diff --git a/man/oe_read.Rd b/man/oe_read.Rd index e360091f..76da5f39 100644 --- a/man/oe_read.Rd +++ b/man/oe_read.Rd @@ -22,6 +22,7 @@ oe_read( never_skip_vectortranslate = FALSE, boundary = NULL, boundary_type = c("spat", "clipsrc"), + remove_gpkg = FALSE, quiet = FALSE ) } @@ -110,6 +111,11 @@ intersect a given area, while \code{clipsrc} also clips the geometries. Check the examples and also \href{https://gdal.org/programs/ogr2ogr.html}{here} for more details.} +\item{remove_gpkg}{Boolean. If \code{TRUE}, the \code{.gpkg} files created by +\code{oe_vectortranslate} are deleted after reading them. This might be useful +when using these functions in a new R package or an external server. +Default value is \code{FALSE}.} + \item{quiet}{Boolean. If \code{FALSE}, the function prints informative messages. Starting from \code{sf} version \href{https://r-spatial.github.io/sf/news/index.html#version-0-9-6-2020-09-13}{0.9.6},