knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, message = FALSE, error = FALSE, comment = "#>", fig.path = "man/figures/README-", fig.height = 4, fig.width = 9, out.width = "100%", dpi = 300 ) if (!interactive()) { options(width = 95) }
The goal of metro is to return data frames from the Washington Metropolitan Area Transit Authority API. Nested lists have been converted to tidy data frames when possible.
The release version of metro (0.9.1) can be installed from CRAN:
install.packages("metro")
Or install the development version from GitHub:
# install.packages("devtools") devtools::install_github("k5cents/metro")
Usage of the WMATA API requires a developer API key. Such a key can be obtained by creating a developer account and subscribing to the free default tier.
The WMATA also provides a demo key to try out the various features of the API. This key should never be used in production, it is rate limited and subject to change at any time.
Sys.setenv(WMATA_KEY = "e13626d03d8e4c03ac07f95541b3091b")
library(metro) packageVersion("metro")
Functions return data frames for easy analysis.
next_train(StationCodes = "A01")
Use coordinates to find station entrances or bus stops near a location. The
geodist::geodist()
function is used to calculate distance from the
supplied coordinates.
# Washington Monument coordinates rail_entrance(Lat = 38.890, Lon = -77.035, Radius = 750)[, -(3:4)]
Date columns with class POSIXt
have been shifted from Eastern time to the UTC
time zone (+5 hours).
bus_position(RouteId = "33")[, 1:8]
Time values are left in Eastern time and are represented using the class
hms
, which counts the seconds since midnight. If the last train on a
Saturday leaves at 1:21 AM (past midnight), this would be represented as
25:21
.
tail(rail_times(StationCode = "E10"))
Some data frames are includes as objects if their functions typically return the same thing every time.
metro_lines # rail_lines() for live
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.