Title: | Seamless Access to World Bank World Development Indicators (WDI) |
---|---|
Description: | Access and analyze the World Bank’s World Development Indicators (WDI) using the corresponding API <https://datahelpdesk.worldbank.org/knowledgebase/articles/889392-about-the-indicators-api-documentation>. WDI provides more than 24,000 country or region-level indicators for various contexts. 'wbwdi' enables users to download, process and work with WDI series across multiple countries, aggregates, and time periods. |
Authors: | Christoph Scheuch [aut, cre, cph]
|
Maintainer: | Christoph Scheuch <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2025-02-25 19:22:09 UTC |
Source: | CRAN |
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" )
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)
# 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)
This function retrieves information about entities (countries and regions) from the World Bank API. It returns a tibble containing various details such as the entity's ID, ISO2 code, name, region information, lending type, capital city, and coordinates.
wdi_get_entities(language = "en", per_page = 1000)
wdi_get_entities(language = "en", per_page = 1000)
language |
A character string specifying the language for the API
response. Defaults to |
per_page |
An integer specifying the number of records to fetch per
request. Defaults to |
This function sends a request to the World Bank API to retrieve data for all supported entities in the specified language. The data is then processed into a tidy format and includes information about the country, such as its ISO code, capital city, geographical coordinates, and additional metadata about regions, income levels, and lending types.
A tibble with the following columns:
A character string representing the entity's unique identifier.
A character string for the name of the entity.
A character string for the ISO2 country code.
A character string for the type of the entity ("country" or "region").
A character string representing the region's unique identifier.
A character string for the name of the region.
A character string for the ISO2 region code.
A character string representing the administrative region's unique identifier.
A character string for the name of the administrative region.
A character string for the ISO2 code of the administrative region.
A character string representing the entity's income level.
A character string for the name of the income level.
A character string for the ISO2 code of the income level.
A character string representing the lending type's unique identifier.
A character string for the name of the lending type.
A character string for the ISO2 code of the lending type.
A character string for the name of the capital city.
A numeric value for the longitude of the entity.
A numeric value for the latitude of the entity.
# Download all entities in English wdi_get_entities() # Download all entities in Spanish wdi_get_entities(language = "zh")
# Download all entities in English wdi_get_entities() # Download all entities in Spanish wdi_get_entities(language = "zh")
This function returns a tibble of supported income levels for querying the World Bank API. The income levels categorize countries based on their gross national income per capita.
wdi_get_income_levels(language = "en")
wdi_get_income_levels(language = "en")
language |
A character string specifying the language code for the API response (default is "en" for English). |
This function provides a reference for the supported income levels, which categorize countries according to their income group as defined by the World Bank. The language parameter allows the results to be returned in different languages as supported by the API.
A tibble with columns that typically include:
An integer identifier for the income level.
A character string representing the ISO2 code for the income level.
The description of the income level (e.g., "Low income", "High income").
https://api.worldbank.org/v2/incomeLevels
# Download all income levels in English wdi_get_income_levels()
# Download all income levels in English wdi_get_income_levels()
This function retrieves a comprehensive list of all indicators supported by the World Bank API. The indicators include metadata such as the indicator ID, name, unit, source, and associated topics. The user can specify the language of the API response and whether to include additional details.
wdi_get_indicators(language = "en", per_page = 32500L)
wdi_get_indicators(language = "en", per_page = 32500L)
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 32,500. Must be a value between 1 and 32,500. |
This function makes a request to the World Bank API to retrieve metadata for all available indicators. It processes the response into a tidy tibble format.
A tibble containing the available indicators and their metadata:
A character string for the ID of the indicator (e.g., "NY.GDP.PCAP.KD").
A character string for the name of the indicator (e.g., "GDP per capita, constant prices").
An integer identifying the data source providing the indicator.
A character string describing the source of the indicator data.
A character string providing additional notes about the data source.
A character string denoting the organization responsible for the data source.
A nested tibble containing (possibly multiple) topics
associated with the indicator, with two columns: an integer
topic_id
and a character topic_name
.
# Download all supported indicators in English wdi_get_indicators() # Download all supported indicators in Spanish wdi_get_indicators(language = "es")
# Download all supported indicators in English wdi_get_indicators() # Download all supported indicators in Spanish wdi_get_indicators(language = "es")
This function returns a tibble of supported languages for querying the World Bank API. The supported languages include English, Spanish, French, Arabic, and Chinese, etc.
wdi_get_languages()
wdi_get_languages()
This function provides a simple reference for the supported languages when querying the World Bank API.
A tibble with three columns:
A character string representing the language code (e.g., "en" for English).
A character string representing the description of the language (e.g., "English").
A character string representing the native form of the language (e.g., "English").
https://api.worldbank.org/v2/languages
# Download all languages wdi_get_languages()
# Download all languages wdi_get_languages()
This function returns a tibble of supported lending types for querying the World Bank API. The lending types classify countries based on the financial terms available to them from the World Bank.
wdi_get_lending_types(language = "en")
wdi_get_lending_types(language = "en")
language |
A character string specifying the language code for the API response (default is "en" for English). |
This function provides a reference for the supported lending types, which classify countries according to the financial terms they are eligible for under World Bank programs. The language parameter allows the results to be returned in different languages as supported by the API.
A tibble with columns that typically include:
An integer for the lending type.
A character string for the ISO2 code of the lending type.
A description of the lending type (e.g., "IBRD", "IDA").
https://api.worldbank.org/v2/lendingTypes
# Download all lending types in English wdi_get_lending_types()
# Download all lending types in English wdi_get_lending_types()
This function returns a tibble of supported regions for querying the World Bank API.The regions include various geographic areas covered by the World Bank's datasets.
wdi_get_regions(language = "en")
wdi_get_regions(language = "en")
language |
A character string specifying the language code for the API response (default is "en" for English). |
This function provides a reference for the supported regions, which
are important for refining queries related to geographic data in the World
Bank's datasets. The region_id
column is unique for seven key regions.
A tibble with the following columns:
An integer identifier for each region.
A character string representing the region code.
A character string representing the ISO2 code for the region.
A character string representing the name of the region, in the specified language.
https://api.worldbank.org/v2/region
# Download all regions wdi_get_regions()
# Download all regions wdi_get_regions()
This function returns a tibble of supported data sources for querying the World Bank API. The data sources include various databases and datasets provided by the World Bank.
wdi_get_sources(language = "en")
wdi_get_sources(language = "en")
language |
A character string specifying the language code for the API response (default is "en" for English). |
This function provides a reference for the supported data sources
and their metadata when querying the World Bank API. The columns
is_data_available
and is_metadata_available
are logical values
derived from the API response, where "Y" indicates availability.
A tibble with six columns:
An integer identifier for the data source.
A character string for the source code.
The name of the data source (e.g., "World Development Indicators").
The last update date of the data source.
A boolean indicating whether data is available.
A boolean indicating whether metadata is available.
The number of concepts defined for the data source.
https://api.worldbank.org/v2/sources
# Download all available data sources in English wdi_get_sources()
# Download all available data sources in English wdi_get_sources()
This function returns a tibble of supported topics for querying the World Bank API. Topics represent the broad subject areas covered by the World Bank's datasets.
wdi_get_topics(language = "en")
wdi_get_topics(language = "en")
language |
A character string specifying the language code for the API response (default is "en" for English). |
This function provides a reference for the supported topics that can be used to refine your queries when accessing the World Bank API. Topics represent different areas of focus for data analysis.
A tibble with three columns:
The unique identifier for the topic.
The name of the topic (e.g., "Education", "Health").
A brief description or note about the topic.
https://api.worldbank.org/v2/topics
# Download all available topics in English wdi_get_topics()
# Download all available topics in English wdi_get_topics()
This function searches for specified keywords across columns in a data frame and returns only the rows where at least one keyword appears in any of the specified columns. It supports nested columns (lists within columns) and provides the option to limit the search to specific columns.
wdi_search(data, keywords, columns = NULL)
wdi_search(data, keywords, columns = NULL)
data |
A data frame to search. It can include nested columns (lists within columns). |
keywords |
A character vector of keywords to search for within the specified columns. The search is case-insensitive. |
columns |
Optional. A character vector of column names to limit the
search to specific columns. If |
A data frame containing only the rows where at least one keyword is
found in the specified columns. The returned data frame has the same
structure as data
.
# Download indicators indicators <- wdi_get_indicators() # Search for keywords "inequality" or "gender" across all columns wdi_search( indicators, keywords = c("inequality", "gender") ) # Search for keywords only within the "indicator_name" column wdi_search( indicators, keywords = c("inequality", "gender"), columns = c("indicator_name") )
# Download indicators indicators <- wdi_get_indicators() # Search for keywords "inequality" or "gender" across all columns wdi_search( indicators, keywords = c("inequality", "gender") ) # Search for keywords only within the "indicator_name" column wdi_search( indicators, keywords = c("inequality", "gender"), columns = c("indicator_name") )