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

Feat/41 check for empty downloads #44

Merged
merged 9 commits into from
Apr 23, 2024
Merged
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
11 changes: 9 additions & 2 deletions R/get_currency_exchange_rates.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ get_currency_exchange_rates <-
year
)

httr2::request(url) %>%
raw_data <- httr2::request(url) %>%
httr2::req_headers("Accept" = "application/json") %>%
httr2::req_timeout(max_seconds) %>%
httr2::req_retry(
Expand All @@ -47,7 +47,14 @@ get_currency_exchange_rates <-
httr2::resp_body_json(simplifyVector = TRUE) %>%
.[["CompactData"]] %>%
.[["DataSet"]] %>%
.[["Series"]] %>%
.[["Series"]]

if (is.null(raw_data)) {
log_error("No data found for the specified quarter: {quarter}.")
stop("No data found for the specified quarter.")
}

raw_data %>%
dplyr::rowwise() %>%
dplyr::mutate(Obs = list(as.data.frame(.data$Obs))) %>%
tidyr::unnest(cols = "Obs") %>%
Expand Down
8 changes: 8 additions & 0 deletions R/get_index_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ get_index_regions <- function() {
ct$get("JSON.stringify(chartDataDMJson)"),
flatten = TRUE
)
if (length(dm_data$categories) == 0L) {
log_error("No data found for Developed Markets.")
stop("No data found for Developed Markets.")
}

log_debug("extracting data from script.")
dm_countries <- c()
Expand Down Expand Up @@ -72,6 +76,10 @@ get_index_regions <- function() {
ct$get("JSON.stringify(chartDataEMJson)"),
flatten = TRUE
)
if (length(data$categories) == 0L) {
log_error("No data found for Emerging Markets.")
stop("No data found for Emerging Markets.")
}

log_debug("extracting data from script.")
em_countries <- c()
Expand Down
5 changes: 5 additions & 0 deletions R/get_ishares_index_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ get_ishares_index_data <- function(url, name, as_of_date) {
# JSON string contains (illegal) UTF8 byte-order-mark!
jsonlite::fromJSON(data_path)$aaData
)
if(length(raw_data) == 0L) {
log_error("No data found for the specified date.")
stop("No data found for the specified date.")
}


fixed_data <- fix_data(raw_data, data_names)

Expand Down