get_pop_queries: Get Population Data (Multiple)

View source: R/get_pop_queries.R

get_pop_queriesR Documentation

Get Population Data (Multiple)

Description

This function is a wrapper for the Population Query API. It allows for querying of multiple Popquery data types for multiple towns and years.

Usage

get_pop_queries(
  token,
  data_types,
  planning_areas,
  years,
  gender = NULL,
  parallel = FALSE
)

Arguments

token

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

data_types

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_areas

Town for which the data should be retrieved.

years

Year for which the data should be retrieved.

gender

Optional, 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.

parallel

Default = FALSE. Whether to run API calls in parallel or sequentially (default). Enabling parallel iterations is highly recommended for when querying multiple data types/years/towns.

Value

A tibble with each row representing a town in a particular year for a particular gender, and columns with the variables returned by the API endpoint. If any API call returns no data, the values will be NA but the row will be returned. However, if all data_types do not return data for that town and year, no row will be returned for it.

Examples

# output with no NA
## Not run: get_pop_queries(token, c("getOccupation", "getLanguageLiterate"),
    c("Bedok", "Yishun"), "2010")
## End(Not run)
## Not run: get_pop_queries(token, c("getEconomicStatus", "getEthnicGroup"),
    "Yishun", "2010", "female")
## End(Not run)

## note behaviour if data types is a mix of those that accept gender params
### only total will have all records
## Not run: get_pop_queries(token, c("getEconomicStatus", "getOccupation", "getLanguageLiterate"),
    "Bedok", "2010")
## End(Not run)
### data type that does not accept gender params will be in gender = Total
## Not run: get_pop_queries(token, c("getEconomicStatus", "getOccupation", "getLanguageLiterate"),
    "Bedok", "2010", gender = "female")
## End(Not run)

# output with some town-year queries without record due to no data
# warning message will show data_type/town/year/gender for which an error occurred
## Not run: get_pop_queries(token, c("getEconomicStatus", "getOccupation"),
    "Bedok", c("2010", "2012"))
## End(Not run) # no records for 2012

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