get_pop_query: Get Population Data

View source: R/get_pop_query.R

get_pop_queryR Documentation

Get Population Data

Description

This function is a wrapper for the Population Query API. It only allows for querying of one data type (i.e. one of the API endpoints) for a particular town and year.

Usage

get_pop_query(token, data_type, planning_area, year, gender = NULL)

Arguments

token

User's API token. This can be retrieved using get_token

data_type

Type of data to be retrieved, should correspond to one of the API endpoints. E.g. to get economic status data, data_type = "getEconomicStatus". The API endpoints can be found on the documentation page.

planning_area

Town for which the data should be retrieved.

year

Year for which the data should be retrieved.

gender

Optional, valid values include male and female. If specified, only records for that gender will be returned. This parameter is only valid for the "getEconomicStatus", "getEthnicGroup", "getMaritalStatus" and "getPopulationAgeGroup" endpoints. If specified for other endpoints, the parameter will be dropped. If gender is not specified for valid endpoints, records for total, male and female will be returned.

Value

A tibble with 1 row and values for all the corresponding variables returned by the API endpoint. If an error occurs, the function will return a NULL value

Examples

# output with no NA
## Not run: get_pop_query(token, "getOccupation", "Yishun", "2010")
## Not run: get_pop_query(token, "getModeOfTransportSchool", "Bishan", "2015", "female")

# note behaviour with gender parameter not specified
## Not run: get_pop_query(token, "getMaritalStatus", "Bedok", "2010")
## Not run: get_pop_query(token, "getEthnicGroup", "Bedok", "2010")
## Not run: get_pop_query(token, "getPopulationAgeGroup", "Bedok", "2010")

# output due to error
## Not run: get_pop_query(token, "getSpokenAtHome", "Bedok", "2043")


onemapsgapi documentation built on Nov. 29, 2022, 9:06 a.m.