Skip to content

Commit

Permalink
Update documentation and default parameters
Browse files Browse the repository at this point in the history
- Changed example code for ids_bulk() to use `\dontrun` instead of `\dontest`. because of CMD Check error related to #51.
- Updated function title and parameter descriptions for clarity.
- Set new default values for `counterparts` and `start_date`.
- changed date logic so it would work with new default start date (previously it would give from 1970  unless a end_date was also specified).
- Added filtering logic to remove rows with NA values beyond the latest year of observed data, (2023) while allowing projections (2031).
- Enhanced tests to validate new defaults and filtering behavior.
  • Loading branch information
t-emery committed Dec 6, 2024
1 parent 0d11db3 commit 7aeac84
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 62 deletions.
2 changes: 1 addition & 1 deletion R/ids_bulk.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#'
#' @export
#' @examplesIf curl::has_internet() && rlang::is_installed("readxl")
#' \donttest{
#' \dontrun{
#' available_files <- ids_bulk_files()
#' data <- ids_bulk(
#' available_files$file_url[1]
Expand Down
37 changes: 33 additions & 4 deletions R/ids_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#' easier to conduct cross-country debt analysis and monitoring.
#'
#' @param geographies A character vector of geography identifiers representing
#' debtor countries and aggregates. Must use World Bank codes from
#' debtor countries and aggregates. Must use `geography_id` from
#' `ids_list_geographies()`:
#' * For individual countries, use ISO3C codes (e.g., "GHA" for Ghana)
#' * For aggregates, use World Bank codes (e.g., "LIC" for low income
#' countries)
#' The IDS database covers low and middle-income countries ("LIC", "LMC",
#' "UMC") and related aggregates only. Cannot contain NA values.
#' The IDS database covers low and middle-income countries and related
#' aggregates only. Cannot contain NA values.
#'
#' @param series A character vector of debt statistics series identifiers that
#' must match the `series_id` column from `ids_list_series()`. Each series
Expand All @@ -38,7 +38,9 @@
#'
#' @param end_date A numeric value representing the ending year (default: NULL).
#' Must be >= 1970 and cannot be earlier than start_date. If NULL, returns
#' data through the most recent available year.
#' data through the most recent available year. Some debt service related
#' series include projections of debt service. For the 2024 data release,
#' debt service projections available through 2031.
#'
#' @param progress A logical value indicating whether to display progress
#' messages during data retrieval (default: FALSE).
Expand Down Expand Up @@ -135,6 +137,10 @@ ids_get <- function(
.progress = progress
)


# Apply specific filtering logic for years beyond latest actual data
debt_statistics <- filter_post_actual_na(debt_statistics)

debt_statistics
}

Expand Down Expand Up @@ -239,6 +245,12 @@ validate_progress <- function(progress) {
}
}


# to be updated manually with each release
# for the 2024-12 IDS release:
latest_year_observied <- 2023
latest_year_projections <- 2031

create_time <- function(start_date, end_date) {
if (!is.null(start_date) && !is.null(end_date)) {
if (start_date > end_date) {
Expand All @@ -247,7 +259,24 @@ create_time <- function(start_date, end_date) {
)
}
paste0("YR", seq(start_date, end_date, by = 1))
} else if (!is.null(start_date)) {
paste0("YR", seq(start_date, latest_year_projections, by = 1))
} else {
"all"
}
}

filter_post_actual_na <- function(data) {
# Identify rows after the latest actual year
data_after_actual <- data |>
filter(.data$year > latest_year_observied)

# Check if all rows for these years have NA in `value`
if (all(is.na(data_after_actual$value))) {
# Remove these rows from the data
data <- data |>
filter(.data$year <= latest_year_observied)
}

data
}
2 changes: 1 addition & 1 deletion man/ids_bulk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

159 changes: 103 additions & 56 deletions man/ids_get.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7aeac84

Please sign in to comment.