From 2b7bced8dc6ee95ea618f580d52801404f98a209 Mon Sep 17 00:00:00 2001 From: Christoph Scheuch <19249734+christophscheuch@users.noreply.github.com> Date: Tue, 13 Jan 2026 22:23:14 +0100 Subject: [PATCH 1/2] Add safe_weo_get() --- DESCRIPTION | 2 +- R/get.R | 32 ++++++++++++++++++++++------ man/add_gdp_column.Rd | 2 +- man/add_gov_exp_column.Rd | 2 +- man/add_gov_exp_share_column.Rd | 2 +- man/add_income_level_column.Rd | 2 +- man/add_population_column.Rd | 2 +- man/add_population_density_column.Rd | 2 +- man/add_population_share_column.Rd | 2 +- man/add_poverty_ratio_column.Rd | 2 +- man/econtools-package.Rd | 4 ++-- 11 files changed, 36 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index be189c3..5cb1a37 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ Description: Provides a consistent set of functions for enriching and analyzing License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Depends: R (>= 4.1) Imports: diff --git a/R/get.R b/R/get.R index ee8e5d7..6ea5228 100644 --- a/R/get.R +++ b/R/get.R @@ -1,7 +1,7 @@ #' @keywords internal #' @noRd get_population <- function(entities, most_recent_only) { - wdi_get( + wbwdi::wdi_get( entities = entities, indicators = "SP.POP.TOTL", most_recent_only = most_recent_only @@ -12,7 +12,7 @@ get_population <- function(entities, most_recent_only) { #' @keywords internal #' @noRd get_poverty_ratio <- function(entities, most_recent_only) { - wdi_get( + wbwdi::wdi_get( entities = entities, indicators = "SI.POV.DDAY", most_recent_only = most_recent_only @@ -23,7 +23,7 @@ get_poverty_ratio <- function(entities, most_recent_only) { #' @keywords internal #' @noRd get_population_density <- function(entities, most_recent_only) { - wdi_get( + wbwdi::wdi_get( entities = entities, indicators = "EN.POP.DNST", most_recent_only = most_recent_only @@ -34,7 +34,7 @@ get_population_density <- function(entities, most_recent_only) { #' @keywords internal #' @noRd get_income_levels <- function(entities) { - wdi_get_entities() |> + wbwdi::wdi_get_entities() |> dplyr::select( id = "entity_id", "income_level_id", @@ -43,11 +43,29 @@ get_income_levels <- function(entities) { dplyr::filter(.data$id %in% entities) } +#' @keywords internal +#' @noRd +safe_weo_get <- function(entities, series, ...) { + publication <- tryCatch( + imfweo::weo_get_latest_publication(), + error = function(e) { + list(year = 2025, release = "Spring") + } + ) + imfweo::weo_get( + entities, + series, + year = publication$year, + release = publication$release, + ... + ) +} + #' @keywords internal #' @noRd get_gdp <- function(entities, most_recent_only, usd = TRUE) { series <- ifelse(usd, "NGDPD", "NGDP") - result <- weo_get(entities, series) |> + result <- safe_weo_get(entities, series) |> dplyr::filter(.data$series_id == series) |> dplyr::select(id = "entity_id", "year", "value") |> dplyr::mutate(value = .data$value * 1e9) @@ -60,7 +78,7 @@ get_gdp <- function(entities, most_recent_only, usd = TRUE) { #' @keywords internal #' @noRd get_gov_exp <- function(entities, most_recent_only) { - result <- weo_get(entities, "GGX") |> + result <- safe_weo_get(entities, "GGX") |> dplyr::filter(.data$series_id == "GGX") |> dplyr::select(id = "entity_id", "year", "value") |> dplyr::mutate(value = .data$value * 1e9) @@ -73,7 +91,7 @@ get_gov_exp <- function(entities, most_recent_only) { #' @keywords internal #' @noRd get_gov_exp_share <- function(entities, most_recent_only) { - result <- weo_get(entities, "GGX_NGDP") |> + result <- safe_weo_get(entities, "GGX_NGDP") |> dplyr::filter(.data$series_id == "GGX_NGDP") |> dplyr::select(id = "entity_id", "year", "value") |> dplyr::mutate(value = .data$value / 100) diff --git a/man/add_gdp_column.Rd b/man/add_gdp_column.Rd index 157cd77..ef8aa9a 100644 --- a/man/add_gdp_column.Rd +++ b/man/add_gdp_column.Rd @@ -35,7 +35,7 @@ A data frame with an additional column containing GDP data. Add GDP to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Add most recent GDP values df <- data.frame(country = c("USA", "CHN", "DEU")) diff --git a/man/add_gov_exp_column.Rd b/man/add_gov_exp_column.Rd index 0a4fc90..b90ded0 100644 --- a/man/add_gov_exp_column.Rd +++ b/man/add_gov_exp_column.Rd @@ -32,7 +32,7 @@ expenditure data. Add Government Expenditure to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Add government expenditure df <- data.frame(country = c("USA", "GBR", "FRA")) diff --git a/man/add_gov_exp_share_column.Rd b/man/add_gov_exp_share_column.Rd index 0643b82..9e469e9 100644 --- a/man/add_gov_exp_share_column.Rd +++ b/man/add_gov_exp_share_column.Rd @@ -32,7 +32,7 @@ expenditure as share of GDP data. Add Government Expenditure as Share of GDP to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Add government expenditure share of GDP df <- data.frame(country = c("USA", "JPN", "AUS")) diff --git a/man/add_income_level_column.Rd b/man/add_income_level_column.Rd index 4d07c87..4f4873f 100644 --- a/man/add_income_level_column.Rd +++ b/man/add_income_level_column.Rd @@ -28,7 +28,7 @@ and name. Add Income Levels to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Add income levels using ISO3 codes df <- data.frame(country = c("USA", "NGA", "IND")) diff --git a/man/add_population_column.Rd b/man/add_population_column.Rd index e3d6cb8..a6f1ee9 100644 --- a/man/add_population_column.Rd +++ b/man/add_population_column.Rd @@ -31,7 +31,7 @@ A data frame with an additional column containing population data. Add Population Column to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Add population data using ISO3 codes df <- data.frame(country = c("USA", "CAN", "MEX")) diff --git a/man/add_population_density_column.Rd b/man/add_population_density_column.Rd index 479aeb4..7fcab3b 100644 --- a/man/add_population_density_column.Rd +++ b/man/add_population_density_column.Rd @@ -33,7 +33,7 @@ data. Add Population Density Column to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Add population density using ISO3 codes df <- data.frame(country = c("FRA", "DEU", "ESP")) diff --git a/man/add_population_share_column.Rd b/man/add_population_share_column.Rd index 88e0a2b..9098537 100644 --- a/man/add_population_share_column.Rd +++ b/man/add_population_share_column.Rd @@ -37,7 +37,7 @@ value divided by population. Add Population Share Column to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Compute value as a share of population df <- data.frame(country = c("USA", "CAN"), value = c(1000, 2000)) diff --git a/man/add_poverty_ratio_column.Rd b/man/add_poverty_ratio_column.Rd index 2db41f3..6a51ce8 100644 --- a/man/add_poverty_ratio_column.Rd +++ b/man/add_poverty_ratio_column.Rd @@ -31,7 +31,7 @@ A data frame with an additional column containing poverty ratio data. Add Poverty Ratio Column to Country Data } \examples{ -\dontshow{if (curl::has_internet()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (curl::has_internet()) withAutoprint(\{ # examplesIf} \donttest{ # Add poverty ratio using ISO3 codes df <- data.frame(country = c("USA", "IND", "BRA")) diff --git a/man/econtools-package.Rd b/man/econtools-package.Rd index f642fb7..a872e07 100644 --- a/man/econtools-package.Rd +++ b/man/econtools-package.Rd @@ -4,9 +4,9 @@ \name{econtools-package} \alias{econtools} \alias{econtools-package} -\title{econtools: Tools to Analyze Economic Data} +\title{econtools: Enrich and Analyze Sovereign-Level Economic Data} \description{ -A collection of tools to facilitate the analysis of economic data. +Provides a consistent set of functions for enriching and analyzing sovereign-level economic data. Economists, data scientists, and financial professionals can use the package to add standardized identifiers, demographic and macroeconomic indicators, and derived metrics such as gross domestic product per capita or government expenditure shares. } \seealso{ Useful links: From 874c29a4e8feb24e2fac9b0b27c2fe560fa10fc9 Mon Sep 17 00:00:00 2001 From: Christoph Scheuch <19249734+christophscheuch@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:01:07 +0100 Subject: [PATCH 2/2] Fix tests --- R/get.R | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/R/get.R b/R/get.R index 6ea5228..7958384 100644 --- a/R/get.R +++ b/R/get.R @@ -1,7 +1,7 @@ #' @keywords internal #' @noRd get_population <- function(entities, most_recent_only) { - wbwdi::wdi_get( + wdi_get( entities = entities, indicators = "SP.POP.TOTL", most_recent_only = most_recent_only @@ -12,7 +12,7 @@ get_population <- function(entities, most_recent_only) { #' @keywords internal #' @noRd get_poverty_ratio <- function(entities, most_recent_only) { - wbwdi::wdi_get( + wdi_get( entities = entities, indicators = "SI.POV.DDAY", most_recent_only = most_recent_only @@ -23,7 +23,7 @@ get_poverty_ratio <- function(entities, most_recent_only) { #' @keywords internal #' @noRd get_population_density <- function(entities, most_recent_only) { - wbwdi::wdi_get( + wdi_get( entities = entities, indicators = "EN.POP.DNST", most_recent_only = most_recent_only @@ -34,7 +34,7 @@ get_population_density <- function(entities, most_recent_only) { #' @keywords internal #' @noRd get_income_levels <- function(entities) { - wbwdi::wdi_get_entities() |> + wdi_get_entities() |> dplyr::select( id = "entity_id", "income_level_id", @@ -46,17 +46,11 @@ get_income_levels <- function(entities) { #' @keywords internal #' @noRd safe_weo_get <- function(entities, series, ...) { - publication <- tryCatch( - imfweo::weo_get_latest_publication(), - error = function(e) { - list(year = 2025, release = "Spring") - } - ) - imfweo::weo_get( + weo_get( entities, series, - year = publication$year, - release = publication$release, + year = 2025, + release = "Spring", ... ) }