Package 'populaR'

Title: World Population Data from the UN
Description: Pulls data from the UN's World Population API, pre-bakes some commonly used datasets
Authors: Chitra Saraswati [aut, cre], Janith Wanniarachchi [aut], James Goldie [aut], Michael Lydeamore [aut]
Maintainer: Chitra Saraswati <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.1003
Built: 2025-01-31 05:40:01 UTC
Source: https://github.com/chitrams/populaR

Help Index


Filter WPP age data by country

Description

Filters WPP age data to a country

Usage

filter_country(.data, country, location_column = location)

Arguments

.data

A tibble containing WPP age data

country

Name of the country

location_column

Name of the location column, unquoted. Default location.

Value

A tibble containing WPP age data for the specified country


Age data from the WPP API

Description

Gets age data in either 1- or 5- year age brackets, potentially segregated by sex

Usage

get_age_data(
  location_id,
  age_bracket,
  by_sex,
  start_year = 1950,
  end_year = 2100,
  .progress = TRUE
)

Arguments

location_id

tibble containing the location id of interest. Typically output from get_id.

age_bracket

integer. Either 1 or 5, indicating the size of the brackets

by_sex

boolean TRUE to segregate results by sex

start_year

integer Start year for data. Default 1950 (as early as available)

end_year

integer End year for data. Default 2100 (as late as available)

.progress

boolean Whether to show progress bar. Default TRUE.

Value

tibble containing location_id, age information, sex, year, in a slightly cleaner format than the raw API call.

Examples

aus_id <- get_id("Australia", type = "locations", search = FALSE, .progress = FALSE)
get_age_data(aus_id$id, age_bracket = 5, start_year = 2023, end_year = 2023, by_sex = TRUE)

Get parameter inputs for population data API

Description

Gets information about indicators (i.e. dataset) and locations for further querying from the WPP API

Usage

get_base_levels(target, .progress = TRUE)

Arguments

target

String, one of "Indicators" or "locations"

.progress

Boolean, whether to show progress bars for query progress. Default TRUE

Value

tibble containing a wide range of information about the requested endpoint

Examples

get_base_levels("Indicators")
get_base_levels("locations")

IDs of indicators

Description

Get numeric IDs of indicators and locations for the WPP API

Usage

get_id(name, type, search = TRUE, .progress = TRUE)

Arguments

name

Name of the variable to search for

type

One of "locations" or "Indicators", which dataset to search

search

Whether to perform simple search/matching. Defaults to TRUE

.progress

Boolean, whether to show progress bars for query progress. Default TRUE

Value

tibble containing only the matching records. Column id is the numeric id which will be needed downstream

Examples

get_id("Australia", type = "locations")

Get WPP data on an indicator from a specific location

Description

Get data for a specific indicator, for a specific location from the WPP API You will need to get the ID of indicators and locations from get_id to pass into this.

Usage

get_indicator_data(
  indicator_id,
  location_id,
  start_year = 1950,
  end_year = 2100,
  .progress = TRUE
)

Arguments

indicator_id

Numeric ID for the indicator. Common choices include:

  • 46: Age by sex in 5 year age groups

  • 47: Age by sex in 1 year age groups

location_id

Numeric ID for the location (country)

start_year

Numeric. Year to start estimates. Minimum 1950, maximum 2100. Default 1950.

end_year

Numeric. Year to end estimates. Minimum 1951, maximum 2100. Default 2100.

.progress

Boolean. Whether to show progress bars for query. Default TRUE.

Details

Note: This function looks for your WPP API key in the environment variable WPP_API_KEY. You can set this using set_wpp_api_key or in your .Renviron file.

Value

tibble with the following columns:

  • locationId: Numeric ID of location

  • location: Description of location

  • iso3: 3-character country code of location

  • iso2: 2-character country code of location

  • locationTypeId:

  • indicatorId: Numeric ID of indicator

  • indicator: Description of indicator

  • indicatorDisplayName: Publishable display name of indicator

Examples

aus_id <- get_id("Australia", type = "locations", search = FALSE, .progress = FALSE)
age_id <- get_id("Population by 5-year age groups and sex", type = "Indicators", search = FALSE, .progress = FALSE)
get_indicator_data(indicator_id = age_id$id, location_id = aus_id$id, start_year = 2020, end_year = 2024)

Five year age data, by country, and year

Description

  • locationId Numeric location for the country

  • location Country

  • year Year of data, in this case 2023

  • ageStart Lower bound of age

  • ageEnd Upper bound of age

  • population Number of individuals

Usage

wpp_age_fiveyr

Format

An object of class grouped_df (inherits from tbl_df, tbl, data.frame) with 5040 rows and 6 columns.


Five year age data, by country, year and sex

Description

  • locationId Numeric location for the country

  • location Country

  • year Year of data, in this case 2023

  • sexId Factor for the sex of an individual. Options are: Male, Female, Both Sexes. Note Both Sexes is the sum of Male and Female.

  • ageStart Lower bound of age

  • ageEnd Upper bound of age

  • population Number of individuals

Usage

wpp_age_sex_fiveyr

Format

An object of class tbl_df (inherits from tbl, data.frame) with 15120 rows and 7 columns.


Five year age data, by country and sex

Description

  • locationId Numeric location for the country

  • location Country

  • year Year of data, in this case 2023

  • sexId Factor for the sex of an individual. Options are: Male, Female, Both Sexes. Note Both Sexes is the sum of Male and Female.

  • population Number of individuals

Usage

wpp_sex_fiveyr

Format

An object of class grouped_df (inherits from tbl_df, tbl, data.frame) with 720 rows and 5 columns.