Learn R Programming

onemapsgapi (version 1.1.0)

get_pop_query: 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)

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

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.

Examples

Run this code
# output with no NA
if (FALSE) get_pop_query(token, "getOccupation", "Yishun", "2010")
if (FALSE) get_pop_query(token, "getModeOfTransportSchool", "Bishan", "2015", "female")

# note behaviour with gender parameter not specified
if (FALSE) get_pop_query(token, "getMaritalStatus", "Bedok", "2010")
if (FALSE) get_pop_query(token, "getEthnicGroup", "Bedok", "2010")
if (FALSE) get_pop_query(token, "getPopulationAgeGroup", "Bedok", "2010")

# output due to error
if (FALSE) get_pop_query(token, "getSpokenAtHome", "Bedok", "2043")

Run the code above in your browser using DataLab