download_wbank_data: Download current country-level World Bank data

View source: R/download_wbank_data.R

download_wbank_dataR Documentation

Download current country-level World Bank data

Description

Uses the wbstats package to download recent country-level data from the World Bank (https://data.worldbank.org).

Usage

download_wbank_data(
  vars = c("SP.POP.TOTL", "AG.LND.TOTL.K2", "EN.POP.DNST", "EN.URB.LCTY",
    "SP.DYN.LE00.IN", "NY.GDP.PCAP.KD"),
  labels = c("population", "land_area_skm", "pop_density", "pop_largest_city",
    "life_expectancy", "gdp_capita"),
  var_def = FALSE,
  silent = FALSE,
  cached = FALSE
)

Arguments

vars

Specify the data items that you want to retrieve.

labels

Give somewhat more informative variable names for the output data frame. Has to match the length of vars and needs to contain valid variable names.

var_def

Do you want to retrieve a data frame containing the World Bank data definitions along with the actual data? Defaults to FALSE.

silent

Whether you want the function to send some status messages to the console. Might be informative as downloading will take some time and thus defaults to TRUE.

cached

Whether you want to download the cached version of the data from the tidycovid19 Github repository instead of retrieving the data from the authorative source. Downloading the cached version is faster and the cache is updated daily. Defaults to FALSE.

Value

If var_def = FALSE, a data frame containing the data and a timestamp variable indicating the time of data retrieval. Otherwise, a list including the data frame with the data followed by a data frame containing the variable definitions.

Examples

df <- download_wbank_data(silent = TRUE, cached = TRUE)
df %>%
  dplyr::select(country, population) %>%
  dplyr::arrange(-population)

lst <- download_wbank_data(silent = TRUE, cached = TRUE, var_def = TRUE)
lst[[1]] %>%
  tidyr::pivot_longer(5:10, names_to = "wbank_variable", values_to = "values") %>%
  dplyr::group_by(wbank_variable) %>%
  dplyr::summarise(non_na = sum(!is.na(values)))


joachim-gassen/tidycovid19 documentation built on March 21, 2024, 6:57 a.m.