wdi_get | R Documentation |
This function retrieves indicator data from the World Bank API for a specified set of entities and indicators. The user can specify one or more indicators, a date range, and other options to tailor the request. The data is processed and returned in a tidy format, including country, indicator, date, and value fields.
wdi_get(
entities,
indicators,
start_year = NULL,
end_year = NULL,
most_recent_only = FALSE,
frequency = "annual",
language = "en",
per_page = 10000L,
progress = TRUE,
source = NULL,
format = "long"
)
entities |
A character vector of ISO 2 or ISO 3-country codes, or
|
indicators |
A character vector specifying one or more World Bank indicators to download (e.g., c("NY.GDP.PCAP.KD", "SP.POP.TOTL")). |
start_year |
Optional integer. The starting date for the data as a year. |
end_year |
Optional integer. The ending date for the data as a year. |
most_recent_only |
A logical value indicating whether to download only
the most recent value. In case of |
frequency |
A character string specifying the frequency of the data ("annual", "quarter", "month"). Defaults to "annual". |
language |
A character string specifying the language for the request,
see wdi_get_languages. Defaults to |
per_page |
An integer specifying the number of results per page for the API. Defaults to 10,000. |
progress |
A logical value indicating whether to show progress messages
during the data download and parsing. Defaults to |
source |
An integer value specifying the data source, see wdi_get_sources. |
format |
A character value specifying whether the data is returned in
|
This function constructs a request URL for the World Bank API,
retrieves the relevant data for the given entities and indicators, and
processes the response into a tidy format. The user can optionally specify a
date range, and the function will handle requests for multiple pages if
necessary. If the progress
parameter is TRUE
, messages will be displayed
during the request and parsing process.
The function supports downloading multiple indicators by sending individual API requests for each indicator and then combining the results into a single tidy data frame.
A tibble with the following columns:
The ISO 3-country code of the country or aggregate for which the data was retrieved.
The ID of the indicator (e.g., "NY.GDP.PCAP.KD").
The year of the indicator data as an integer.
Optional. The quarter of the indicator data as integer.
Optional. The month of the indicator data as integer.
The value of the indicator for the given country and date.
# Download single indicator for multiple entities
wdi_get(c("USA", "CAN", "GBR"), "NY.GDP.PCAP.KD")
# Download single indicator for a specific time frame
wdi_get(c("USA", "CAN", "GBR"), "DPANUSSPB",
start_year = 2012, end_year = 2013)
# Download single indicator for monthly frequency
wdi_get("AUT", "DPANUSSPB",
start_year = 2012, end_year = 2015, frequency = "month")
# Download single indicator for quarterly frequency
wdi_get("NGA", "DT.DOD.DECT.CD.TL.US",
start_year = 2012, end_year = 2015, frequency = "quarter")
# Download single indicator for all entities and disable progress bar
wdi_get("all", "NY.GDP.PCAP.KD", progress = FALSE)
# Download multiple indicators for multiple entities
wdi_get(c("USA", "CAN", "GBR"), c("NY.GDP.PCAP.KD", "SP.POP.TOTL"))
# Download indicators for different sources
wdi_get("DEU", "SG.LAW.INDX", source = 2)
wdi_get("DEU", "SG.LAW.INDX", source = 14)
# Download indicators in wide format
wdi_get(c("USA", "CAN", "GBR"), c("NY.GDP.PCAP.KD"),
format = "wide")
wdi_get(c("USA", "CAN", "GBR"), c("NY.GDP.PCAP.KD", "SP.POP.TOTL"),
format = "wide")
# Download most recent value only
wdi_get("USA", "SP.POP.TOTL", most_recent_only = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.