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

Add ids_list_series() and ids_list_series_topics() functions #16

Merged
merged 10 commits into from
Oct 20, 2024
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
^Meta$
^\.github$
_pkgdown.yml
^data-raw$
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(ids_list_series)
export(ids_list_series_topics)
import(cli)
import(dplyr)
import(httr2)
Expand Down
23 changes: 23 additions & 0 deletions R/ids_list_series.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#' List Available Series from the World Bank International Debt Statistics API
#'
#' This function returns a tibble with available series from the World Bank International Debt Statistics
#' (IDS) API. Each series provides data on various debt-related indicators.
#'
#' @return A tibble containing the available series and their metadata:
#' \describe{
#' \item{series_id}{The unique identifier for the series (e.g., "BN.CAB.XOKA.CD").}
#' \item{series_name}{The name of the series (e.g., "Current account balance (current US$)").}
#' \item{source_id}{The ID of the data source providing the indicator.}
christophscheuch marked this conversation as resolved.
Show resolved Hide resolved
#' \item{source_name}{The name or description of the source of the indicator data.}
#' \item{source_note}{Additional notes or descriptions about the data source.}
#' \item{source_organization}{The organization responsible for the data source.}
#' }
#'
#' @export
#'
#' @examples
#' ids_list_series()
#'
ids_list_series <- function() {
series
}
21 changes: 21 additions & 0 deletions R/ids_list_series_topics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' List Available Series-Topic combinations from the World Bank International Debt Statistics API
#'
#' This function returns a tibble with available series-topic combinations from the World Bank
#' International Debt Statistics (IDS) API. Each row provides a mapping from series to topic, with
#' the possibility of multiple topic per series.
#'
#' @return A tibble containing the available series and their topics:
#' \describe{
#' \item{series_id}{The unique identifier for the series (e.g., "BM.GSR.TOTL.CD").}
#' \item{topic_id}{The unique identifier for the topic (e.g., 3).}
#' \item{topic_name}{The name of the topic (e.g., "External Debt").}
#' }
#'
#' @export
#'
#' @examples
#' ids_list_series_topics()
#'
ids_list_series_topics <- function() {
series_topics
}
Binary file added R/sysdata.rda
Binary file not shown.
42 changes: 42 additions & 0 deletions data-raw/wbids_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
devtools::load_all()

# Prepare geography data ----------------------------------------------------------------------


# Prepare series data -------------------------------------------------------------------------

series_raw <- perform_request("series")

series_processed <- series_raw[[1]]$concept[[1]]$variable |>
bind_rows() |>
select(
series_id = "id",
series_name = "value"
)

# pak::pak("tidy-intelligence/r-wbwdi")
indicators <- wbwdi::wdi_get_indicators()

series_extended <- series_processed |>
left_join(indicators, join_by(series_id == indicator_id))

series <- series_extended|>
select(series_id, series_name, source_id, source_name, source_note, source_organization)

# Prepare counterpart data --------------------------------------------------------------------


# Prepare series-topics data ------------------------------------------------------------------

series_topics <- series_extended |>
select(series_id, topics) |>
tidyr::unnest(topics)

# Store all data in single rda file -----------------------------------------------------------

# TODO: add other data sources later here as well

usethis::use_data(
series, series_topics,
christophscheuch marked this conversation as resolved.
Show resolved Hide resolved
overwrite = TRUE, internal = TRUE
)
27 changes: 27 additions & 0 deletions man/ids_list_series.Rd

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

25 changes: 25 additions & 0 deletions man/ids_list_series_topics.Rd

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

Loading