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 |
Filters WPP age data to a country
filter_country(.data, country, location_column = location)
filter_country(.data, country, location_column = location)
.data |
A tibble containing WPP age data |
country |
Name of the country |
location_column |
Name of the location column, unquoted. Default |
A tibble containing WPP age data for the specified country
Gets age data in either 1- or 5- year age brackets, potentially segregated by sex
get_age_data( location_id, age_bracket, by_sex, start_year = 1950, end_year = 2100, .progress = TRUE )
get_age_data( location_id, age_bracket, by_sex, start_year = 1950, end_year = 2100, .progress = TRUE )
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. |
tibble containing location_id, age information, sex, year, in a slightly cleaner format than the raw API call.
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)
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)
Gets information about indicators (i.e. dataset) and locations for further querying from the WPP API
get_base_levels(target, .progress = TRUE)
get_base_levels(target, .progress = TRUE)
target |
String, one of "Indicators" or "locations" |
.progress |
Boolean, whether to show progress bars for query progress. Default TRUE |
tibble
containing a wide range of information about the requested endpoint
get_base_levels("Indicators") get_base_levels("locations")
get_base_levels("Indicators") get_base_levels("locations")
Get numeric IDs of indicators and locations for the WPP API
get_id(name, type, search = TRUE, .progress = TRUE)
get_id(name, type, search = TRUE, .progress = TRUE)
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 |
tibble
containing only the matching records. Column id
is the numeric
id which will be needed downstream
get_id("Australia", type = "locations")
get_id("Australia", type = "locations")
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.
get_indicator_data( indicator_id, location_id, start_year = 1950, end_year = 2100, .progress = TRUE )
get_indicator_data( indicator_id, location_id, start_year = 1950, end_year = 2100, .progress = TRUE )
indicator_id |
Numeric ID for the indicator. Common choices include:
|
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. |
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.
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
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)
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)
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
wpp_age_fiveyr
wpp_age_fiveyr
An object of class grouped_df
(inherits from tbl_df
, tbl
, data.frame
) with 5040 rows and 6 columns.
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
wpp_age_sex_fiveyr
wpp_age_sex_fiveyr
An object of class tbl_df
(inherits from tbl
, data.frame
) with 15120 rows and 7 columns.
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
wpp_sex_fiveyr
wpp_sex_fiveyr
An object of class grouped_df
(inherits from tbl_df
, tbl
, data.frame
) with 720 rows and 5 columns.