-
Notifications
You must be signed in to change notification settings - Fork 0
/
incidents-rail.R
52 lines (51 loc) · 1.67 KB
/
incidents-rail.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#' Rail Incidents
#'
#' Reported rail incidents (significant disruptions and delays to normal
#' service). The data is identical to WMATA's Metrorail Service Status feed.
#'
#' @format A data frame with 1 row incident and 5 variables:
#' \describe{
#' \item{IncidentID}{Unique identifier for an incident.}
#' \item{Description}{Free-text description of the incident.}
#' \item{IncidentType}{Free-text description of the incident type. Usually
#' Delay or Alert but is subject to change at any time.}
#' \item{LinesAffected}{Character vector of line codes (e.g.: RD; or BL; OR;
#' or BL; OR; RD;).}
#' \item{DateUpdated}{Date and time (UTC) of last update.}
#' }
#'
#' @inheritParams wmata_key
#' @examples
#' \dontrun{
#' rail_incidents()
#' }
#' @return Data frame of all rail incidents.
#' @seealso <https://developer.wmata.com/docs/services/54763641281d83086473f232/operations/54763641281d830c946a3d77>
#' @family Incident APIs
#' @importFrom tibble as_tibble tibble
#' @export
rail_incidents <- function(api_key = wmata_key()) {
dat <- wmata_api(
path = "Incidents.svc/json/Incidents",
flatten = TRUE,
level = 1,
api_key = api_key
)
if (no_data_now(dat)) {
message("No rail incidents reported")
return(empty_rail_incidents)
}
# Deprecated: DelaySeverity EmergencyText EndLocationFullName PassengerDelay
# StartLocationFullName
dat <- dat[, -c(3:6, 8)]
dat[[4]] <- strsplit(dat[[4]], ";\\s?")
dat[[5]] <- api_time(dat[[5]])
tibble::as_tibble(dat)
}
empty_rail_incidents <- tibble::tibble(
IncidentID = character(),
IncidentType = character(),
LinesAffected = list(),
DateUpdated = as.POSIXct(character()),
Description = character()
)