Returns next train arrival information for one or more stations. Will return
an empty set of results when no predictions are available. Use "All" for the
StationCodes
parameter to return predictions for all stations.
next_train(StationCodes = NULL, api_key = wmata_key())
A tibble 1 row per arrival with 9 variables:
Number of cars on a train, usually 6 or 8, but might also NA
.
Abbreviated version of the final destination for a train. This is similar to what is displayed on the signs at stations.
When DestinationCode
is populated, this is the
full name of the destination station, as shown on the WMATA website.
Denotes the track this train is on, but does not necessarily equate to Track 1 or Track 2. With the exception of terminal stations, predictions at the same station with different Group values refer to trains on different tracks.
Two-letter abbreviation for the line (e.g.: RD, BL, YL, OR, GR,
or SV). May also be NA
for trains with no passengers.
Station code for where the train is arriving. Useful
when passing in All as the StationCodes
parameter. Use this value in
other rail-related APIs to retrieve data about a station.
Full name of the station where the train is arriving.
Useful when passing in "All" as the StationCodes
parameter.
Minutes until arrival. Can be a numeric value, 0 (arriving),
-1 (boarding), or NA
.
Character vector of station codes. For all predictions,
use NULL
(default) or "All".
Subscription key which provides access to this API. Defaults
Sys.getenv("WMATA_KEY")
via wmata_key()
.
Data frame of train arrivals.
For terminal stations (e.g.: Greenbelt, Shady Grove, etc.), predictions may be displayed twice.
Some stations have two platforms (e.g.: Gallery Place, Fort Totten, L'Enfant Plaza, and Metro Center). To retrieve complete predictions for these stations, be sure to pass in both StationCodes.
For trains with no passengers, the DestinationName
will be "No Passenger".
Other Real-Time Predictions:
next_bus()
if (FALSE) {
next_train(StationCodes = c("A02", "B02"))
}