Package 'datagovsgR'

Title: Call Real Time APIs from Data Gov Singapore
Description: A wrapper for the Data.gov.sg developer resources, which provide real time and historical information, ranging from carpark availability to weather forecasts. The functions makes the API calls for a given date and time, before returning the relevant information in a data frame. All APIs are supported, less the IPOS one which is not returning any data. Relevant information can be found here <https://data.gov.sg/developer>.
Authors: Clinton Wong <[email protected]>
Maintainer: Clinton Wong <[email protected]>
License: MIT + file LICENSE
Version: 1.0.1
Built: 2024-09-26 06:20:00 UTC
Source: CRAN

Help Index


Carpark Availability

Description

This functions calls upon the carpark availability API from data.gov.sg and processes the returning page.

Usage

carpark_availability(date_time = "")

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

Value

A dataframe containing the carpark id, type, last update, total lots, and current lots.

Examples

carpark_availability()
carpark_availability(date = "2019-06-05T10:10:10")
carpark_availability(date = "2018-12-01T19:32:56")

ParseApiDate

Description

Helper function to check if the date was input correctly before returning a url to be called by the GET function. Also returns an error if the API called can only provide data for a specific date-time, and not date only.

Usage

parse_api_date(api, input_date = "", summary)

Arguments

api

The api to be called, i.e. api = "environment/air-temperature"

input_date

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS or YYYY-MM-DD

summary

Returns an error if the user inputs a date only time when not supported by the API.

Value

A url to be called by the API.


ParseApiOutput

Description

Helper function to extract the content returned from the API. Returns the status code otherwise.

Usage

parse_api_output(inputcontent)

Arguments

inputcontent

Takes the output of the GET function, runs an error check and returns the parsed output.

Value

The extracted content if not error has occured. Otherwise, the error message is returned.


PM2.5

Description

This functions calls upon the PM2.5 API from data.gov.sg and returns a data frame of the different measures of PM2.5 across 5 different areas in Singapore. This data provided by the API is updated hourly from NEA.

Usage

pm25(date_time = "")

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

Details

Note that this function is different from the 'pm25_summary' function, which returns the PM2.5 measures for a given day.

Value

A dataframe containing various PM2.5 measures across 5 corners of Singapore

Examples

pm25()
pm25(date_time = "2019-11-08T17:30:00")
pm25(date_time = "2018-01-04T09:16:17")

PM2.5 Summary

Description

This functions calls upon the PM2.5 API from data.gov.sg and returns a data frame of the different measures of the PM2.5 across 5 different areas in Singapore for each hour. This data provided by the API is updated hourly from NEA.

Usage

pm25_summary(date = "")

Arguments

date

Defaults to current (SGD) time. Format: YYYY-MM-DD

Details

Note that this function is different from the 'pm25' function, which returns the PM2.5 measures for a given date and time.

Value

A dataframe containing various PM2.5 measures across 5 corners of Singapore and time of day. Dependent on the data availible, not all results range from 0000 to 2300.

Examples

pm25_summary()
pm25_summary(date = "2019-11-08")
pm25_summary(date = "2018-01-04")

PSI(PoullutantStandardIndex)

Description

This functions calls upon the PSI API from data.gov.sg and returns a data frame of the different measures of the PSI across 5 different areas in Singapores and the overall measure for the given data-time. This data provided by the API is updated hourly.

Usage

psi(date_time = "")

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

Details

Note that this function is different from the 'PSI_summary' function, which returns the PSI measures for a given day.

Value

A dataframe containing various PSI measures across 5 corners of Singapore

Examples

psi()
psi(date = "2019-11-08T17:30:00")
psi(date = "2018-01-04T09:16:17")

PSI(PoullutantStandardIndex) Summary

Description

This functions calls upon the PSI API from data.gov.sg and returns a data frame of the different measures of the PSI across 5 different areas in Singapores and the overall measure for the given date. This data provided by the API is updated hourly.

Usage

psi_summary(date = "")

Arguments

date

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

Details

Note that this function is different from the 'PSI' function, which returns the PSI measures for a given date-time.

Value

A dataframe containing various PSI measures across 5 corners of Singapore and time of day. Dependent on the data availible, not all results range from 0000 to 2300.

Examples

psi_summary()
psi_summary(date = "2019-11-08")
psi_summary(date = "2018-01-04")

Taxi Availability

Description

This functions calls upon the taxi availability API from data.gov.sg and returns a data frame of the locations of all availible taxis.

Usage

taxi_availability(date_time = "")

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

Value

A dataframe containing the longitude and latitude values of availible taxis.

Examples

taxi_availability()
taxi_availability(date = "2019-08-07T09:30:00")
taxi_availability(date = "2018-06-05T13:45:00")

Traffic Images

Description

This functions calls upon the Traffic Images API from data.gov.sg and returns links to images of live traffic conditions along expressways and Woodlands & Tuas Checkpoints, including details of the camera location. This data provided by the API is updated every minute.

Usage

traffic_images(date_time = "")

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

Value

A dataframe containing links to the traffic images of current traffic conditions

Examples

traffic_images()
traffic_images(date = "2022-07-01T15:32:45")
traffic_images(date = "2021-02-11T14:11:07")

UVI(Ultra-violet Index)

Description

This functions calls upon the UVI API from data.gov.sg and returns a data frame of the different measures of the UVI across Singapore and returns the closest UVI value presently and for the past few hours. This data provided by the API is updated hourly.

Usage

uvi(date_time = "")

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

Value

A dataframe containing the current and past hourly UVI

Examples

uvi()
uvi(date = "2022-09-03T16:45:23")
uvi(date = "2021-12-06T11:01:55")

Weather Forecast

Description

This functions calls upon the weather forecast API from data.gov.sg and returns a data frame containing different metrics of the forecast. 2-hour, 24-hour and 4-day forecasts are availible. This data provided by the API is updated half-hourly.

Usage

weather_forecast(date_time = "", forecast = "2-hour")

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

forecast

Defaults to "2-hour". Also availible for "24-hour" and "4-day"

Value

A dataframe the forecast for a given date and time, and forecast period.

Examples

weather_forecast()
weather_forecast(date = "2019-11-08T17:30:00", forecast = "24-hour")
weather_forecast(date = "2018-01-04T09:16:17", forecast = "4-day")

Weather Reading

Description

This functions calls upon the weather reading API from data.gov.sg and returns a list containing the air temperature, rainfall, relative humidity, wind direction and speed across Singapore. Data is updated every 5 minutes for the rainfall API, and every half minute for the other 4 API from NEA.

Usage

weather_reading(date_time = "", simplify = FALSE)

Arguments

date_time

Defaults to current (SGD) time. Format: YYYY-MM-DDTHH:MM:SS

simplify

Defaults to FALSE. Otherwise, simplify = TRUE would return a data frame where all 5 metrics are joined according to weather stations, but return several NAs, as most weather stations collect rainfall data only.

Details

This API takes slighlty longer than the other APIs in the package as 5 APIs are wrapped within this function.

Value

A dataframe containing various weather readings from weather stations

Examples

weather_reading()
weather_reading(date = "2019-11-08T17:30:00")
weather_reading(date = "2018-01-04T09:16:17", simplify = TRUE)