get_theme: Get Theme Data from OneMap.Sg

View source: R/get_theme.R

get_themeR Documentation

Get Theme Data from OneMap.Sg

Description

This function is a wrapper for the Retrieve Theme API. It returns the data as cleaned tibbles.

Usage

get_theme(token, theme, extents = NULL, return_info = FALSE, read = "tibble")

Arguments

token

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

theme

OneMap theme in its QUERYNAME format. A tibble of available themes can be retrieved using search_themes

extents

Optional, Location Extents for search. This should be in the format "Lat1,%20Lng1,Lat2,%20Lng2". For more information, consult the API Documentation.

return_info

Default = FALSE. If FALSE, function only returns a tibble for query results. If TRUE, function returns output as a list containing a tibble for query information and a tibble for query results.

read

Optional, format to read output. Valid parameters are tibble, sf and rgdal. For "sf" objects, specify read = "sf" and for "sp" objects use read = "rgdal". Defaults to tibble if any other value is used. Please ensure the sf package is installed, else this parameter return a tibble.

Value

If no error occurs:

query_info

A 1 x 7 tibble containing information about the query. The variables are FeatCount, Theme_Name, Category, Owner, DateTime.date, DateTime.timezone_type, DateTime.timezone

query_result

Returned if return_info = TRUE. A tibble containing the data retrieved from the query. The columns and rows vary depending on theme and user specification, however all tibbles will contain the variables: NAME, DESCRIPTION, ADDRESSPOSTALCODE, ADDRESSSTREETNAME, Lat, Lng, ICON_NAME

If an error occurs, the output will be NULL, along with a warning message. For non-error queries where 0 results are returned, the output will be query_info, along with a warning message.

Examples

# returns a tibble of output
## Not run: get_theme(token, "hotels")
## Not run: get_theme(token, "monuments",
    extents = "1.291789,%20103.7796402,1.3290461,%20103.8726032")
## End(Not run)

# returns a sf dataframe
## Not run: get_theme(token, "hotels", read = "sf")

# returns a list of status tibble and output tibble
## Not run: get_theme(token, "funeralparlours", return_info = TRUE)

# error: output is NULL, warning message shows status code
## Not run: get_theme("invalid_token", "hotels")

# error: output is NULL, warning message shows error message from request
## Not run: get_theme(token, "non-existent-theme")

# error: output is \code{query_info}, warning message query did not return any records
## Not run: get_theme(token, "ura_parking_lot", "1.291789,%20103.7796402,1.3290461,%20103.8726032")

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