Skip to content

Commit 0d11420

Browse files
authored
Fix xml fallback (#177)
* fix xml fallback * rebuild roxygen2 docs * prevent repeated messages about using cached metadata * rerender docs
1 parent e448597 commit 0d11420

File tree

6 files changed

+55
-21
lines changed

6 files changed

+55
-21
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# spanishoddata (development version)
22

3+
## Bug fixes
4+
5+
* Fixed failing fallback on XML when Amazon S3 is unavailable.
6+
37
# spanishoddata 0.2.1 (2025-07-29)
48

59
## Bug fixes

R/available-data.R

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,18 @@ spod_available_data_v1 <- function(
145145
fs::dir_create(metadata_folder)
146146
}
147147

148+
s3_successful <- FALSE
149+
148150
if (use_s3) {
149151
files_table <- tryCatch(
150152
{
151-
spod_available_data_s3(ver = 1, force = force, quiet = quiet)
153+
files_table_s3 <- spod_available_data_s3(
154+
ver = 1,
155+
force = force,
156+
quiet = quiet
157+
)
158+
s3_successful <- TRUE
159+
files_table_s3
152160
},
153161
error = function(e) {
154162
message(
@@ -306,7 +314,7 @@ spod_available_data_v1 <- function(
306314
)
307315

308316
# add known file sizes from cached data
309-
if (use_s3) {
317+
if (s3_successful) {
310318
# replace remote file sizes for v1
311319
replacement_file_sizes_distr <- files_table |>
312320
dplyr::filter(grepl("mitma-distr", .data$local_path)) |>
@@ -497,10 +505,18 @@ spod_available_data_v2 <- function(
497505
fs::dir_create(metadata_folder)
498506
}
499507

508+
s3_successful <- FALSE
509+
500510
if (use_s3) {
501511
files_table <- tryCatch(
502512
{
503-
spod_available_data_s3(ver = 2, force = force, quiet = quiet)
513+
files_table_s3 <- spod_available_data_s3(
514+
ver = 2,
515+
force = force,
516+
quiet = quiet
517+
)
518+
s3_successful <- TRUE
519+
files_table_s3
504520
},
505521
error = function(e) {
506522
message(
@@ -630,7 +646,7 @@ spod_available_data_v2 <- function(
630646
)
631647

632648
# add known file sizes from cached data
633-
if (use_s3) {
649+
if (s3_successful) {
634650
files_table$remote_file_size_mb <- round(
635651
files_table$file_size_bytes / 1024^2,
636652
2

R/get-zones.R

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,17 @@ spod_get_zones_v1 <- function(
148148
metadata <- spod_available_data(
149149
ver = 1,
150150
data_dir = data_dir,
151-
check_local_files = FALSE
151+
check_local_files = FALSE,
152+
quiet = quiet
152153
)
153154

154155
# Ensure the raw data is downloaded and extracted
155-
spod_download_zones_v1(zones, data_dir, quiet)
156+
spod_download_zones_v1(
157+
zones = zones,
158+
data_dir = data_dir,
159+
quiet = quiet,
160+
metadata = metadata
161+
)
156162

157163
# check if gpkg files are already saved and load them if available
158164
expected_gpkg_path <- fs::path(
@@ -375,6 +381,7 @@ spod_clean_zones_v1 <- function(zones_path, zones) {
375381
#' @param zones The zones for which to download the data. Can be `"districts"` (or `"dist"`, `"distr"`, or the original Spanish `"distritos"`) or `"municipalities"` (or `"muni"`, `"municip"`, or the original Spanish `"municipios"`).
376382
#' @param data_dir The directory where the data is stored.
377383
#' @param quiet Boolean flag to control the display of messages.
384+
#' @param metadata Optional metadata table returned by `spod_available_data()`.
378385
#' @return A `character` string containing the path to the downloaded and extracted file.
379386
#' @keywords internal
380387
spod_download_zones_v1 <- function(
@@ -389,17 +396,21 @@ spod_download_zones_v1 <- function(
389396
"municipios"
390397
),
391398
data_dir = spod_get_data_dir(),
392-
quiet = FALSE
399+
quiet = FALSE,
400+
metadata = NULL
393401
) {
394402
zones <- match.arg(zones)
395403
zones <- spod_zone_names_en2es(zones)
396404

397-
metadata <- spod_available_data(
398-
ver = 1,
399-
data_dir = data_dir,
400-
use_s3 = TRUE,
401-
check_local_files = FALSE
402-
)
405+
if (is.null(metadata)) {
406+
metadata <- spod_available_data(
407+
ver = 1,
408+
data_dir = data_dir,
409+
use_s3 = TRUE,
410+
check_local_files = FALSE,
411+
quiet = quiet
412+
)
413+
}
403414

404415
# download id relation files if missing
405416
relation_files <- metadata[

man/spod_cite.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/spod_convert.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/spod_download_zones_v1.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)