From 6a4c17e1c08f1178dc48d4b0a74d2a5e9297bb21 Mon Sep 17 00:00:00 2001 From: krlong68 Date: Wed, 11 Oct 2023 15:18:52 -0700 Subject: [PATCH 1/5] added overwrite functionality --- R/metadata.R | 4 ++-- R/utils.R | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/R/metadata.R b/R/metadata.R index ba5d8c1..35efc9e 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -154,14 +154,14 @@ get_metadata <- function( else { db_path <- file.path(cache_directory, "metadata.0.2.3.parquet") - if (!file.exists(db_path)){ + #if (!file.exists(db_path)){ report_file_sizes(remote_url) sync_remote_file( remote_url, db_path, progress(type = "down", con = stderr()) ) - } + #} table <- duckdb() |> dbConnect(drv = _, read_only = TRUE) |> diff --git a/R/utils.R b/R/utils.R index 0e455a1..6308373 100644 --- a/R/utils.R +++ b/R/utils.R @@ -61,7 +61,11 @@ get_default_cache_dir <- function() { #' @return `NULL`, invisibly #' @keywords internal sync_remote_file <- function(full_url, output_file, ...) { - if (!file.exists(output_file)) { + user_over <- NA + if (file.exists(output_file)) { + user_over <- tolower(readline(prompt = "Cached file already exists. Overwrite? (Y/N):")) + } + if (!file.exists(output_file) | user_over == "y") { output_dir <- dirname(output_file) dir.create(output_dir, recursive = TRUE, @@ -70,7 +74,7 @@ sync_remote_file <- function(full_url, output_file, ...) { cli_alert_info("Downloading {full_url} to {output_file}") tryCatch( - GET(full_url, write_disk(output_file), ...) |> stop_for_status(), + GET(full_url, write_disk(output_file, overwrite = TRUE), ...) |> stop_for_status(), error = function(e) { # Clean up if we had an error file.remove(output_file) From 6a85cf1fa768e440025ee39def6c768e59f2000e Mon Sep 17 00:00:00 2001 From: krlong68 Date: Wed, 11 Oct 2023 15:53:35 -0700 Subject: [PATCH 2/5] removed commented lines --- R/metadata.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/metadata.R b/R/metadata.R index 35efc9e..06837af 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -154,14 +154,12 @@ get_metadata <- function( else { db_path <- file.path(cache_directory, "metadata.0.2.3.parquet") - #if (!file.exists(db_path)){ report_file_sizes(remote_url) sync_remote_file( remote_url, db_path, progress(type = "down", con = stderr()) ) - #} table <- duckdb() |> dbConnect(drv = _, read_only = TRUE) |> From 561ec1d82236a4e71e0ff8da51cc1b418da2bfc4 Mon Sep 17 00:00:00 2001 From: krlong68 Date: Wed, 11 Oct 2023 15:55:18 -0700 Subject: [PATCH 3/5] adjust indents --- R/metadata.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/metadata.R b/R/metadata.R index 06837af..4cfc2be 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -154,12 +154,12 @@ get_metadata <- function( else { db_path <- file.path(cache_directory, "metadata.0.2.3.parquet") - report_file_sizes(remote_url) - sync_remote_file( - remote_url, - db_path, - progress(type = "down", con = stderr()) - ) + report_file_sizes(remote_url) + sync_remote_file( + remote_url, + db_path, + progress(type = "down", con = stderr()) + ) table <- duckdb() |> dbConnect(drv = _, read_only = TRUE) |> From 4c1491d9fd4e969b65e31c56c0d94ad563fe6b35 Mon Sep 17 00:00:00 2001 From: krlong68 Date: Wed, 18 Oct 2023 12:12:56 -0700 Subject: [PATCH 4/5] using menu prompt and checking for interactive session --- R/utils.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 6308373..ad64c9a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -58,14 +58,19 @@ get_default_cache_dir <- function() { #' Synchronises a single remote file with a local path #' @importFrom httr write_disk GET stop_for_status #' @importFrom cli cli_abort cli_alert_info +#' @importFrom rlang is_interactive #' @return `NULL`, invisibly #' @keywords internal sync_remote_file <- function(full_url, output_file, ...) { user_over <- NA if (file.exists(output_file)) { - user_over <- tolower(readline(prompt = "Cached file already exists. Overwrite? (Y/N):")) + if (is_interactive()) { + user_over <- menu(c("Yes", "No"), title = "Cached file alread exists. Overwrite?") + } else { + user_over <- 1 + } } - if (!file.exists(output_file) | user_over == "y") { + if (!file.exists(output_file) | user_over == 1) { output_dir <- dirname(output_file) dir.create(output_dir, recursive = TRUE, From bf03f936e645a4ba8308a69b9681d9d868fcb4e8 Mon Sep 17 00:00:00 2001 From: krlong68 Date: Wed, 18 Oct 2023 12:14:03 -0700 Subject: [PATCH 5/5] | > || --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index ad64c9a..dd757f8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -70,7 +70,7 @@ sync_remote_file <- function(full_url, output_file, ...) { user_over <- 1 } } - if (!file.exists(output_file) | user_over == 1) { + if (!file.exists(output_file) || user_over == 1) { output_dir <- dirname(output_file) dir.create(output_dir, recursive = TRUE,