Skip to contents

These help pages document the lower-level API to individually download, read, and tidy data. For a higher-level API that works across all data sets, see:

Usage

download_wb(file_name, indicator, range_years)

read_wb(file_name, data_dir = Sys.getenv("DXGAP_DATADIR"))

tidy_wb(data, year = NULL)

Arguments

file_name

A string containing the name of the file to be read.

indicator

A string indicating the label of the data set as documented in the World Bank API. For instance, "SP.POP.TOTL".

range_years

The range of the years to be downloaded as a string.

data_dir

Path containing the directory to read the data from. Defaults to the path set by the environment variable "DXGAP_DATADIR".

data

A tibble returned from the corresponding read_() function.

year

A year to filter the data by. Defaults to NULL, returning data for all years.

Value

download_wb() returns invisibly the file path in which data are stored.

read_wb() a tibble containing the data set.

tidy_wb() a tibble. This is a tidied version of the input tibble.

Details

The data sets currently available from World Bank in this package are:

  • urban population

  • total population

  • population density

  • gdp

Source

The World Bank API is documented at https://datahelpdesk.worldbank.org/knowledgebase/articles/898581.

Examples

if (FALSE) {
pop_urban <- download_wb(
  file_name = paste_dataset_name_date("wb", dataset = "pop_urban", file_ext = ".csv"),
  indicator = "SP.URB.TOTL.IN.ZS",
  range_years = "2015:2023"
)
pop_density <-
  download_wb(
    file_name = paste_dataset_name_date("wb", dataset = "pop_density", file_ext = ".csv"),
    indicator = "EN.POP.DNST",
    range_years = "2015:2023"
  )
pop_total <- download_wb(
  file_name = paste_dataset_name_date("wb", dataset = "pop_total", file_ext = ".csv"),
  indicator = "SP.POP.TOTL",
  range_years = "2015:2023"
)
gdp <- download_wb(
  file_name = paste_dataset_name_date("wb", dataset = "gdp", file_ext = ".csv"),
  indicator = "NY.GDP.MKTP.CD",
  range_years = "2015:2023"
)
}
if (FALSE) {
read_wb("wb_pop_urban_2023-07-28.csv")
}
if (FALSE) {
read_wb("wb_pop_urban_2023-07-28.csv") |>
  tidy_wb()
}