Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m-muecke/worldbank
R client for the World Bank Indicators and PIP APIs
https://github.com/m-muecke/worldbank
api indicators poverty r r-package worldbank worldbank-api
Last synced: 2 months ago
JSON representation
R client for the World Bank Indicators and PIP APIs
- Host: GitHub
- URL: https://github.com/m-muecke/worldbank
- Owner: m-muecke
- License: other
- Created: 2023-12-06T14:24:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-17T08:38:19.000Z (4 months ago)
- Last Synced: 2024-09-18T03:36:46.971Z (4 months ago)
- Topics: api, indicators, poverty, r, r-package, worldbank, worldbank-api
- Language: R
- Homepage: https://m-muecke.github.io/worldbank/
- Size: 5.48 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(tibble.print_min = 5L, tibble.print_max = 5L)
```# worldbank
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/m-muecke/worldbank/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/m-muecke/worldbank/actions/workflows/R-CMD-check.yaml)
[![CRAN status](https://www.r-pkg.org/badges/version/worldbank)](https://CRAN.R-project.org/package=worldbank)## Overview
**worlbank** provides a simple interface to the following [World Bank](https://datahelpdesk.worldbank.org/knowledgebase/articles/889386-developer-information-overview) APIs:
- [Indicators API v2](https://datahelpdesk.worldbank.org/knowledgebase/articles/889392-about-the-indicators-api-documentation)
- [Poverty and Inequality Platform (PIP) API](https://pip.worldbank.org/api).
- [Finances One API](https://financesone.worldbank.org)The main difference to other packages is that it's a modern implementation using the [httr2](https://httr2.r-lib.org) package
and supports all available endpoints and parameters.The `worldbank` package provides a set of functions to interact with various endpoints of the World Bank Indicators API.
Each function is designed to retrieve specific types of data, making it easier to access and analyze World Bank datasets.
Below is an overview of the available endpoints and their corresponding functions in the package:- **Languages** (`wb_language`): Retrieves a list of all languages supported by the World Bank API. Useful for obtaining language-specific data.
- **Lending Types** (`wb_lending_type`): Fetches information about different lending types as recognized by the World Bank.
- **Income Levels** (`wb_income_level`): Allows users to access data about various income levels defined by the World Bank.
- **Sources** (`wb_source`): Provides details about the different data sources available within the World Bank’s datasets.
- **Topics** (`wb_topic`): Lists all topics covered by the World Bank API, helping users to narrow down their data search to specific areas of interest.
- **Regions** (`wb_region`): Offers information on different geographical regions as categorized by the World Bank.
- **Countries** (`wb_country`): Enables access to detailed data about individual countries, including socio-economic and developmental indicators.
- **Country Indicators** (`wb_country_indicator`): Specific to retrieving indicators for a particular country or countries, allowing for more targeted data analysis.
- **Indicators** (`wb_indicator`): This endpoint gives users access to a wide array of indicators used by the World Bank in its data analysis and reports.## Installation
You can install the released version of **worldbank** from [CRAN](https://CRAN.R-project.org) with:
```{r, eval = FALSE}
install.packages("worldbank")
```And the development version from [GitHub](https://github.com/) with:
```{r, eval = FALSE}
# install.packages("pak")
pak::pak("m-muecke/worldbank")
```## Usage
worldbank functions are prefixed with `wb_` and follow the naming convention of the [World Bank API v2](https://datahelpdesk.worldbank.org/knowledgebase/articles/889392-about-the-indicators-api-documentation).
```{r demo}
library(worldbank)# filter by specific country
wb_country(c("US", "DE"))# or fetch all (default)
wb_country()# search for specific indicator
ind <- wb_indicator()
ind <- subset(
ind,
grepl("GDP", id, fixed = TRUE) & source_value == "World Development Indicators"
)
ind# fetch indicator data for specific or all countries (default)
gdp <- wb_country_indicator("NY.GDP.MKTP.CD", c("US", "DE", "FR", "CH", "JP"))
gdp
``````{r plotting, message = FALSE, echo = FALSE, dpi = 300}
library(ggplot2)ggplot(gdp, aes(x = date, y = value, color = country_code)) +
geom_line() +
theme_minimal() +
theme(
plot.title = element_text(face = "bold"),
panel.grid.major.y = element_line(color = "black", linewidth = 0.2),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.text = element_text(color = "black"),
axis.title = element_blank()
) +
scale_y_continuous(
labels = scales::label_currency(scale_cut = scales::cut_short_scale())
) +
labs(title = "GDP (current US$)", color = "Country")
```## Related work
* [wbstats](https://github.com/gshs-ornl/wbstats): R package for searching and downloading data from the World Bank API
* [WDI](https://github.com/vincentarelbundock/WDI): R package to download World Bank data
* [pipr](https://github.com/worldbank/pipr): R client for the PIP Worldbank API