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,
  return_spatial = FALSE
)

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.

return_spatial

Default = FALSE. If FALSE, function returns a tibble. If TRUE, function returns an sf 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, an error will be raised, along with the API's error message and status code. 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", return_spatial = TRUE)

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

# error: throws an error with error message and status code
## Not run: get_theme("invalid_token", "hotels")

# error: throws an error with error message and status code
## 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 June 8, 2025, 10:05 a.m.