NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true")
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  purl = NOT_CRAN
)
library(pipr)

The pipr package allows to easily query the PIP API from R.

Here are a few examples to get you started:

Using default options

By default, get_stats() returns all available

For the most recent data available.

get_stats()

Basic options

Filter by country

# Specify ONE country
get_stats(country = "ALB")

# Specify MULTIPLE countries
get_stats(country = c("ALB", "CHN"))

Filter by year

By default, get_stats will only return data if a survey is available for the requested country and the requested year.

# Survey year available
get_stats(country = "ALB", year = 2012)         # single year
get_stats(country = "ALB", year = c(1996,2012)) # multiple years

# Survey year NOT available - Empty response
get_stats(country = "ALB", year = 2000)

# Most Recent Value available
get_stats(country = "ALB", year = "MRV")

Modify the poverty line

get_stats(country = "ALB", povline = 3.2)

Other features

Get estimates when survey year is not available

The fill_gaps argument triggers the interpolation / extrapolation of poverty estimates when surveys are not available for a given year.

# fill_gaps = FALSE (default)
get_stats(country = "HTI")
# fill_gaps = TRUE
get_stats(country = "HTI", fill_gaps = TRUE)

Compute aggregates

get_stats() can also be used to compute aggregate welfare statistics for sub-regions. Only World Bank regions are currently available, but more sub-regional groupings will become available in the future.

# World Bank aggregate
get_stats(country = "all", subgroup = "wb_regions")
# List of World Bank regions
get_regions()


worldbank/pipr documentation built on Dec. 22, 2024, 7:08 a.m.