datagovsgR

Description of datagovsgR

The goal of this package is to create API wrappers for the APIs found on the GovTech. GovTech is the Singapore department focused on data and technology, which currently has a list of API tools for developers to leverage on, found on their website. These developer API tools are publicly accessible, containing tools such as realtime weather readings, carpark availability and locations of available taxis. The API wrappers are listed below.


Carpark Availability

This functions calls upon the carpark availability API from data.gov.sg and processes the returning page, returning a dataframe containing the carpark id, type, last update, total lots, and current lots. A date-time has to be specified, otherwise the default is set to return the current date-time.

carpark_availability(date = "2019-06-05T10:10:10") %>% head()
#> Closest timestamp: 2019-06-05T10:09:27+08:00
#>     id type         last_update total_lots availability_lots
#> 1 HE12    C 2019-06-05T10:08:42         83                 0
#> 2  HLM    C 2019-06-05T10:08:52        583               183
#> 3  RHM    C 2019-06-05T10:08:42        322               128
#> 4 BM29    C 2019-06-05T10:08:49         97                49
#> 5  Q81    C 2019-06-05T10:08:48         96                21
#> 6  C20    C 2019-06-05T10:08:30        173                 0


PM 2.5

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. There are 2 functions, the pm25 which returns the data for a given date-time, and pm25_summary which returns the data summary for a given date.

# pm25(date_time = "2018-01-04T09:16:17")
# pm25_summary(date = "2018-01-04") %>% head()


PoullutantStandardIndex (PSI)

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. There are 2 functions, the psi which returns the data for a given date-time, and psi_summary which returns the data summary for a given date.

psi(date = "2019-11-08T17:30:00") %>% head()
#> Closest timestamp:
#> data frame with 0 columns and 0 rows
psi_summary(date = "2018-01-04") %>% head()
#> [1] "No data returned from API."


Taxi Availability

This functions calls upon the taxi availability API from data.gov.sg and returns a data frame of the locations of all availible taxis in longitude and latitude values. A date-time has to be specified, otherwise the default is set to return the current date-time.

taxi_availability(date = "2019-08-07T09:30:00") %>% head()
#> Timestamp: 2019-08-07T09:29:55+08:00
#> Availible Taxis: 4586
#>       long     lat
#> 1 103.6142 1.25267
#> 2 103.6235 1.28648
#> 3 103.6236 1.30047
#> 4 103.6238 1.28678
#> 5 103.6275 1.31123
#> 6 103.6282 1.31332


Weather Forecast

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. It then returns a dataframe containing the forecast which is dependent on the date-time and parameter of forecast. This data provided by the API is updated half-hourly. A date-time has to be specified, otherwise the default is set to return the current date-time.

A 2-hour forecast returns the general forecast for each area in Singapore for the next 2-hours; a 24-hour forecast returns the general forecast for the next day along with the weather metrics; a 4-day forecast returns the general forecast for each of the next four days.

weather_forecast(date = "2019-11-08T17:30:00", forecast = "2-hour") %>% head()
#> Closest timestamp: 2019-11-08T17:30:00+08:00
#> Forecast valid to: 2019-11-08T19:30:00+08:00
#>          area            forecast
#> 1  Ang Mo Kio Partly Cloudy (Day)
#> 2       Bedok Partly Cloudy (Day)
#> 3      Bishan Partly Cloudy (Day)
#> 4    Boon Lay Partly Cloudy (Day)
#> 5 Bukit Batok Partly Cloudy (Day)
#> 6 Bukit Merah Partly Cloudy (Day)
weather_forecast(date = "2018-01-04T09:16:17", forecast = "4-day")
#> Closest timestamp: 2018-01-04T05:16:00+08:00
#>         date                                   general_forecast
#> 1 2018-01-05 Late morning and early afternoon thundery showers.
#> 2 2018-01-06                        Afternoon thundery showers.
#> 3 2018-01-07 Late morning and early afternoon thundery showers.
#> 4 2018-01-08                        Afternoon thundery showers.
#>   relative_humidity_low relative_humidity_high temperature_low temperature_high
#> 1                    65                     95              23               32
#> 2                    60                     95              24               33
#> 3                    60                     95              24               33
#> 4                    60                     95              24               33
#>   wind_direction wind_speed_low wind_speed_high
#> 1       VARIABLE              5              15
#> 2              S              5              15
#> 3             SE             10              20
#> 4            ENE             10              20


Weather Reading

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. A date-time has to be specified, otherwise the default is set to return the current date-time. Do note that this API takes slighlty longer than the other APIs in the package as 5 APIs are wrapped within this function.

The simplify parameter is FALSE on default, returning a list of each of the 5 metrics. 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.

weather_reading(date = "2019-11-08T17:30:00")
#> $air_temp
#> # A tibble: 14 × 2
#>    station_id value
#>    <chr>      <dbl>
#>  1 S117        29.7
#>  2 S50         30.1
#>  3 S107        29.6
#>  4 S43         30.6
#>  5 S44         29.4
#>  6 S121        30.5
#>  7 S106        29.5
#>  8 S111        30.4
#>  9 S122        29.7
#> 10 S60         30.7
#> 11 S115        28.5
#> 12 S116        30.1
#> 13 S104        30.2
#> 14 S100        30.3
#> 
#> $rainfall
#> # A tibble: 0 × 0
#> 
#> $relative_humidity
#> # A tibble: 0 × 0
#> 
#> $wind_direction
#> # A tibble: 15 × 2
#>    station_id value
#>    <chr>      <int>
#>  1 S109         297
#>  2 S117         262
#>  3 S50          245
#>  4 S107         232
#>  5 S43          289
#>  6 S108         229
#>  7 S44          286
#>  8 S106         255
#>  9 S122         312
#> 10 S60          246
#> 11 S115         302
#> 12 S24          283
#> 13 S116         266
#> 14 S104         291
#> 15 S100         266
#> 
#> $wind_speed
#> # A tibble: 15 × 2
#>    station_id value
#>    <chr>      <dbl>
#>  1 S109         4.6
#>  2 S117         3.6
#>  3 S50          3.1
#>  4 S107        11.9
#>  5 S43          4.3
#>  6 S108         6.9
#>  7 S44          6.3
#>  8 S106         2.5
#>  9 S122         5.7
#> 10 S60          3.6
#> 11 S115         6.8
#> 12 S24          4.9
#> 13 S116        16.4
#> 14 S104         5.4
#> 15 S100         2.9