Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.
Open
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
14 changes: 6 additions & 8 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
}
report_file_sizes(remote_url)
sync_remote_file(
remote_url,
db_path,
progress(type = "down", con = stderr())
)

table <- duckdb() |>
dbConnect(drv = _, read_only = TRUE) |>
Expand Down
13 changes: 11 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +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, ...) {
if (!file.exists(output_file)) {
user_over <- NA
if (file.exists(output_file)) {
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 == 1) {
output_dir <- dirname(output_file)
dir.create(output_dir,
recursive = TRUE,
Expand All @@ -70,7 +79,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)
Expand Down