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")
#> Closest timestamp: 2018-01-04T09:00:00+08:00
#>   west east central south north
#> 1   13   18      13    11    10
pm25_summary(date = "2018-01-04") %>% head()
#>                   timestamp west east central south north
#> 1 2018-01-04T01:00:00+08:00   10   10       9     4    11
#> 2 2018-01-04T02:00:00+08:00   17   15       7     7    16
#> 3 2018-01-04T03:00:00+08:00    7    9       4     8    12
#> 4 2018-01-04T04:00:00+08:00    5   12       3    15    19
#> 5 2018-01-04T05:00:00+08:00    9   11       8    14    13
#> 6 2018-01-04T06:00:00+08:00    5   11      13    11    15


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: 2019-11-08T17:00:00+08:00
#>              psi_measures west national east central south north
#> 1            o3_sub_index   12       20   13      20    13    17
#> 2 pm10_twenty_four_hourly   33       39   35      29    39    30
#> 3          pm10_sub_index   33       39   35      29    39    30
#> 4            co_sub_index    4        9    9       2     4     5
#> 5 pm25_twenty_four_hourly   21       22   21      18    22    19
#> 6           so2_sub_index    8        8    3       3     8     5
psi_summary(date = "2018-01-04") %>% head()
#>                   date_time   region o3_sub_index pm10_twenty_four_hourly
#> 1 2018-01-04T01:00:00+08:00     west            5                      22
#> 2 2018-01-04T01:00:00+08:00 national            9                      27
#> 3 2018-01-04T01:00:00+08:00     east            9                      24
#> 4 2018-01-04T01:00:00+08:00  central            5                      18
#> 5 2018-01-04T01:00:00+08:00    south            4                      27
#> 6 2018-01-04T01:00:00+08:00    north            7                      23
#>   pm10_sub_index co_sub_index pm25_twenty_four_hourly so2_sub_index
#> 1             22            6                       9             6
#> 2             27            7                      13             6
#> 3             24            2                      11             2
#> 4             18            7                      11             2
#> 5             27            7                      12             4
#> 6             23            6                      13             3
#>   co_eight_hour_max no2_one_hour_max so2_twenty_four_hourly pm25_sub_index
#> 1              0.64               17                      9             39
#> 2              0.73               38                      9             52
#> 3              0.21               28                      3             47
#> 4              0.73               35                      3             45
#> 5              0.70               38                      6             49
#> 6              0.57               15                      4             52
#>   psi_twenty_four_hourly o3_eight_hour_max
#> 1                     39                12
#> 2                     52                20
#> 3                     47                20
#> 4                     45                11
#> 5                     49                 9
#> 6                     52                17


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: 52 × 2
#>    station_id value
#>    <chr>      <int>
#>  1 S105           0
#>  2 S77            0
#>  3 S109           0
#>  4 S117           0
#>  5 S64            0
#>  6 S90            0
#>  7 S61            0
#>  8 S114           0
#>  9 S11            0
#> 10 S50            0
#> # ℹ 42 more rows
#> 
#> $relative_humidity
#> # A tibble: 14 × 2
#>    station_id value
#>    <chr>      <dbl>
#>  1 S117        83  
#>  2 S50         72.7
#>  3 S107        82  
#>  4 S43         71.4
#>  5 S44         78  
#>  6 S121        72.7
#>  7 S106        79  
#>  8 S111        66.6
#>  9 S122        79.9
#> 10 S60         66.3
#> 11 S115        82.8
#> 12 S116        80  
#> 13 S104        71.7
#> 14 S100        72.9
#> 
#> $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