Helper functions and advanced examples"

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

Specify parameters at the country level

This function can be very handy is you maintain a list of countries and parameters in a table like the one below. Note: This function only works with survey years. There is no fill_gaps option available

# Read values from a table
data("sample_input")
sample_input
# Use table values to send a request to the API
# Only works for survey years
povcalnet_cl(country = sample_input$country,
             povline = sample_input$poverty_line,
             year = sample_input$year,
             ppp = sample_input$ppp)

Helper functions

Information table

povcalnet_info() %>%
glimpse()

Get all available countries from a World Bank region

get_countries(c("ECA"))

Get all available countries from a World Bank income classification

get_countries(c("LIC"))

Combining functions

Pass different poverty lines to countries from different income groups

income_groups <- c("LIC", "LMC", "UMC")
poverty_lines <- c(1.9, 3.2, 5.5)
map2_df(income_groups, poverty_lines, ~povcalnet(country = get_countries(.x),
                                                 povline = .y,
                                                 year = 2015,
                                                 aggregate = TRUE)
        )


Try the povcalnetR package in your browser

Any scripts or data that you put into this service are public.

povcalnetR documentation built on July 8, 2020, 6:48 p.m.