Skip to content

Commit

Permalink
Merge branch 'main' into remove-manual-loggger-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
cjyetman authored Apr 23, 2024
2 parents e7942fb + 847dd09 commit c4f7059
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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
11 changes: 10 additions & 1 deletion R/get_index_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ get_index_regions <- function() {
ct$get("JSON.stringify(chartDataDMJson)"),
flatten = TRUE
)
if (length(dm_data$categories) == 0L) {
logger::log_error("No data found for Developed Markets.")
stop("No data found for Developed Markets.")
}

log_debug("extracting data from script.")

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

logger::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

0 comments on commit c4f7059

Please sign in to comment.