Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove_gpkg argument #237

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -220,6 +224,7 @@ oe_get = function(
download_only = FALSE,
skip_vectortranslate = FALSE,
never_skip_vectortranslate = FALSE,
remove_gpkg = FALSE,
quiet = FALSE
) {

Expand Down Expand Up @@ -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,
...
)
Expand Down
7 changes: 7 additions & 0 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ oe_read = function(
never_skip_vectortranslate = FALSE,
boundary = NULL,
boundary_type = c("spat", "clipsrc"),
remove_gpkg = FALSE,
quiet = FALSE
) {

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)
}
Expand Down
6 changes: 6 additions & 0 deletions man/oe_get.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/oe_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.