Skip to content

Commit

Permalink
version 0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
k5cents authored and cran-robot committed Oct 29, 2023
1 parent 9bbbbfb commit 73a0932
Show file tree
Hide file tree
Showing 37 changed files with 280 additions and 124 deletions.
14 changes: 8 additions & 6 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: metro
Title: Washington Metropolitan Area Transit Authority API
Version: 0.9.1
Version: 0.9.2
Authors@R:
person(given = "Kiernan",
family = "Nicholls",
Expand All @@ -12,19 +12,21 @@ Description: The Washington Metropolitan Area Transit Authority
'Metro Transparent Data Sets API' <https://developer.wmata.com/> to
return data frames of transit data for easy analysis.
License: MIT + file LICENSE
URL: https://github.com/kiernann/metro, https://kiernann.com/metro/
URL: https://github.com/kiernann/metro,
https://kiernann.github.io/metro/
BugReports: https://github.com/kiernann/metro/issues
Depends: R (>= 2.10)
Imports: geodist (>= 0.0.6), hms (>= 1.0.0), httr (>= 1.4.2), jsonlite
(>= 1.7.1), tibble (>= 3.0.4)
Suggests: covr (>= 3.5.1), spelling (>= 2.2), testthat (>= 3.0.0)
Suggests: covr (>= 3.5.1), mockr (>= 0.1), spelling (>= 2.2), testthat
(>= 3.0.0)
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.1.1
RoxygenNote: 7.2.3
NeedsCompilation: no
Packaged: 2021-02-26 17:31:14 UTC; kiernan
Packaged: 2023-10-28 15:43:16 UTC; kiernan
Author: Kiernan Nicholls [aut, cre]
Maintainer: Kiernan Nicholls <kiernann@protonmail.com>
Repository: CRAN
Date/Publication: 2021-03-01 10:10:02 UTC
Date/Publication: 2023-10-28 21:50:08 UTC
71 changes: 36 additions & 35 deletions MD5
@@ -1,24 +1,24 @@
6c555673d99fb2d1313c824520bd933c *DESCRIPTION
3ee8ff10e376317dd99b8001b54cef7f *DESCRIPTION
837175cb0f91fb7784032b5309ed2137 *LICENSE
5f18a4c5befa00d42d1bea7039846893 *NAMESPACE
e1cd6135ba0d766a37fad1a6bdb7a43a *NEWS.md
494da41d7cd659fd8951ca746b7a4b77 *R/api.R
38e04ec9f4d9b511ca4b97f2308d8bc6 *NAMESPACE
4dbe5078c063bf9cc9cf863366386dc7 *NEWS.md
ba398d158d38f4b1f666bf5b6899a5a0 *R/api.R
5ac5bc2836cf56752daef77b399525c0 *R/bus-departs.R
f1ae87c1b4d509e04ba3cd5ab4db83fb *R/bus-path.R
7801eaf0924a08da020454a1a65d8ac5 *R/bus-position.R
c8d849f705c60a08f8906cdbb7505b91 *R/bus-routes.R
53b862c8daec6a1f8ab185cf88ffffd9 *R/bus-schedule.R
f8f88e70613ac5942080047784876720 *R/bus-stops.R
4ac27deaec98cc67584396c4e4c18726 *R/data.R
9b2287ce3fa559ea4cbbeedf3a6db988 *R/incidents-bus.R
70fb8f7b03ad8f227d3bbfd45727c605 *R/incidents-elevator.R
af0791a9171f4c48d84134b57d257c69 *R/incidents-rail.R
64c7916bb1cb7590b217240136c41428 *R/key.R
340471e16b3a76f52136af3cbd3f8926 *R/metro.R
fc5238cf2dcb544c38fae11efb017840 *R/next-bus.R
6db88f85eccc3c7e8b9e1c9bce791ed6 *R/next-train.R
e2ceac330ea91c88637c4fb26b1bdffb *R/bus-position.R
2c547a32c714e42707d5a094d543c7a5 *R/bus-routes.R
41870d23912b27d3f5510e7974b5c432 *R/bus-schedule.R
baece55bca2c7a2a6cd87a68bb840e36 *R/bus-stops.R
fec772a3d2eebf046c624cf0c4664788 *R/data.R
2203907fb509263f6b8640338d49200f *R/incidents-bus.R
b82464a76982d0aeaf898156c1e44e6c *R/incidents-elevator.R
95fc9ed517fbf434e4839bce7dbd93ee *R/incidents-rail.R
d4450e6ea1007935c6a9dfef493413b2 *R/key.R
9af7b7cd6936fe9539917ac0e3567d19 *R/metro-package.R
9d101bf58c45a4ab46bdb9e88a353a4c *R/next-bus.R
8e58fa8e660261e887dfe53a9dcee8b7 *R/next-train.R
bed700111d315bd7957ce13424c7b83e *R/rail-destination.R
7a6150065088a649978841bd6a11189d *R/rail-entrance.R
006542b6fd6799c01210fa30dc9e590c *R/rail-entrance.R
890a26035db152e02d9bd336c2c0e843 *R/rail-info.R
806852e4b6e3562b6405f92442564f92 *R/rail-lines.R
8b6e2e1bc530a0863b5953bb339ae03f *R/rail-path.R
Expand All @@ -27,29 +27,30 @@ bed700111d315bd7957ce13424c7b83e *R/rail-destination.R
516fb27f6da093444db57ff42bae6aab *R/rail-times.R
3bcf787631277edf03a1cf62fbd813d8 *R/standard-routes.R
7f96f93cbfef233dc3a4ae3f802f5b76 *R/track-circuits.R
1ec1ca8d60b3da371709e1a055e8537e *R/utils.R
1797d7a55b135b7a12c4e40b66753dd4 *README.md
f34c6e2397c2c38b67287bbe86531b69 *R/utils.R
89fc300f93aab6b874efb437889a885d *README.md
9a9262bb243e77fe3fbc372e946cc0d3 *data/metro_lines.rda
00e16a8865c8ffdb2065ef360ab44aec *data/metro_routes.rda
f7065223551863ab4b643c61791b1eed *data/metro_stations.rda
ca19d7efb76aa729c4998bde941d1173 *data/metro_stops.rda
231a1ffd6d41c8cd90f680af1601511f *inst/WORDLIST
e55374caa496cf5a9dd121829f834b02 *inst/WORDLIST
421a8ce8fdcb52851ffaf161416f8aea *man/bus_departs.Rd
981795aeaab90c6a96ca40610ffbe268 *man/bus_incidents.Rd
73833cb61641c7d98bff570ce48f7b7f *man/bus_path.Rd
9064e4b1c1336756753eb03ce3db74b8 *man/bus_position.Rd
1a275b76368123c7ab8d579d626b468d *man/bus_routes.Rd
d693b8596274ec5b85ed397404609aab *man/bus_position.Rd
133e3a30a03813cd41fbed63acc6110f *man/bus_routes.Rd
e5f208dc63d8c5c6dedf5f97847f65e8 *man/bus_schedule.Rd
e9a111a5d1ba84be3e37eb2794206973 *man/bus_stops.Rd
07cd1a6aa1f2207a9ab017ec3f37e57d *man/elevator_incidents.Rd
2853946eeb5721454dc99c0bca0538f1 *man/figures/logo.png
42ef4e6e0e27bcfe7a4b572f9154e9df *man/metro.Rd
cfa1f1d9f10eae3eff3748d30e30405b *man/metro-package.Rd
69a2f4814b2fba32386640ec6d9a7ed3 *man/metro_lines.Rd
da95388ada8bb60388af8666ecdacb5e *man/metro_routes.Rd
d9b4925fb9888b74ae3824adc32cd8cd *man/metro_routes.Rd
9adc772bc200fd4e16fa71fee30e7c46 *man/metro_stations.Rd
8797c79b23a3f84191114d62d66c5ac9 *man/metro_stops.Rd
6abf91283922f320f64491102e891218 *man/next_bus.Rd
0e02bad4b1b699a84d9cf205d23a3c39 *man/next_train.Rd
a5d9c8ddcd9340487f6d55d44261c522 *man/no_data_now.Rd
f9001fa1e69c21cacf731d3f780908a8 *man/rail_destination.Rd
1b90e93f71ea63771eb90233a44a2798 *man/rail_entrance.Rd
abed5abb77347820ae0cb364175754fa *man/rail_incidents.Rd
Expand All @@ -61,26 +62,26 @@ dab8423c92e7ac2ef6f65674738eb59a *man/rail_stations.Rd
8cdd4a79ddb9efe4fbbf815f206aef05 *man/standard_routes.Rd
5f4919d40c0ce3416774907c764d52a3 *man/station_info.Rd
4db598cd4d618ea923796ce7637bc757 *man/track_circuits.Rd
19b0da93232ab524f7bb73ca127ce957 *man/wmata_api.Rd
ef821c4fa10dfbfa03cfb061f2fb1d14 *man/wmata_api.Rd
a86fc417889fc36b3ee540810ebc3fff *man/wmata_key.Rd
0622a97a2aaa3c342f09636052c2d7f5 *tests/spelling.R
dfa4e8c38d40fde94c6db8b57955c2f2 *tests/testthat.R
519f8c277d6886c6322a9823eda36f83 *tests/testthat/test-api.R
adc80ecd42d86d2e058323d5a0fdc2e7 *tests/testthat/test-bus-departs.R
cc7989b14d2a091f6269fac7f9a206eb *tests/testthat/test-bus-path.R
85d13a9990601f3b8510c253ad46c1e7 *tests/testthat/test-bus-positions.R
67d1661a28760732dc98517d2de81258 *tests/testthat/test-bus-positions.R
a4e6f9b75e641e86f4d6f99a91f28e33 *tests/testthat/test-bus-routes.R
2a261efed78945854f596cea75080c93 *tests/testthat/test-bus-schedules.R
009e5a8c06a587bc3c2690ed066e5164 *tests/testthat/test-bus-stops.R
2c9e232064881267c85e227824175cf5 *tests/testthat/test-incidents-bus.R
766e7ea125bdbd0c4173e76fcf75cd44 *tests/testthat/test-incidents-elevator.R
a42efbb64a2dc6b1b5d6e0dce99678de *tests/testthat/test-incidents-rail.R
b8ec388a2527b5c6f20a978af4394f7c *tests/testthat/test-key.R
c67305822e3ca8d732bb4675da656027 *tests/testthat/test-next-bus.R
05a603a2a0a6186653a62942e1f4e361 *tests/testthat/test-next-train.R
eec19ba9b3fbea1cda5530302c791c4a *tests/testthat/test-bus-stops.R
1e6a092e7ff379ef661e267e2591e22b *tests/testthat/test-incidents-bus.R
ecfeb61b5afd00d635548116f41afaa1 *tests/testthat/test-incidents-elevator.R
9713d81de69f098aad637d570760c806 *tests/testthat/test-incidents-rail.R
12d247a3eff49ccd5f73b723415e9eed *tests/testthat/test-key.R
edc8d6ef1e4c2572ba091c69ce902a3e *tests/testthat/test-next-bus.R
682f6e0967077a7ba43d1ea5efa42326 *tests/testthat/test-next-train.R
d8bd52c0b9b81be0e13f2e93a2a1b4bc *tests/testthat/test-rail-dest.R
0e96e0d0895f4e8648a8a1641958e29c *tests/testthat/test-rail-entrance.R
027b5f77cde674c344b13d2c6d8e8921 *tests/testthat/test-rail-info.R
b45b0655c3f2307c92d0d2b890a33c69 *tests/testthat/test-rail-entrance.R
2eac5057df1c651ace8767925a1e4783 *tests/testthat/test-rail-info.R
c7c15f4c08ed17f5ec93f62e3c7b5897 *tests/testthat/test-rail-lines.R
826a2ee43c46cebdd30e54aa7106f9a7 *tests/testthat/test-rail-path.R
c4947f98139f6cb75bf38fb4788f593a *tests/testthat/test-rail-position.R
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -10,6 +10,7 @@ export(bus_stops)
export(elevator_incidents)
export(next_bus)
export(next_train)
export(no_data_now)
export(rail_destination)
export(rail_entrance)
export(rail_incidents)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
@@ -1,3 +1,11 @@
# metro 0.9.2

* Update to new package doc help page.
* `bus_schedule()` now correctly merges both directions (thanks Prof. Moore!)
* No longer calls `unlist()` on affected lines of length one.
* Messages given instead of warnings when empty tibbles returned.
* These conditions are tested with `no_data_now()` and `mockr::with_mock()`.

# metro 0.9.1

* Covered most [JSON endpoints](https://developer.wmata.com/docs/services/)
Expand Down
5 changes: 2 additions & 3 deletions R/api.R
Expand Up @@ -6,8 +6,7 @@
#'
#' This function was modified from 'zamorarr/wmata' on GitHub:
#' <https://github.com/zamorarr/wmata/blob/master/R/api.r>
#' @param type The API base type to call, one of "Rail" or "Bus".
#' @param endpoint The API endpoint (e.g., "jStations").
#' @param path The path to an API endpoint (e.g., "Bus.svc/json/jStopSchedule")
#' @param query Additional queries also passed, possibly your key if need be.
#' @param ... Arguments passed to [jsonlite::fromJSON()] for parsing.
#' @param level If parsed JSON is a list, select only this element. Useful if
Expand All @@ -26,7 +25,7 @@
wmata_api <- function(path, query = NULL, ..., level, api_key = wmata_key()) {
resp <- httr::RETRY(
verb = "GET",
url = "https://api.wmata.com",,
url = "https://api.wmata.com",
path = path,
query = query,
httr::accept_json(),
Expand Down
18 changes: 11 additions & 7 deletions R/bus-position.R
Expand Up @@ -39,12 +39,13 @@
#' specified.
#' @param Lon Center point Longitude, required if Latitude and Radius are
#' specified.
#' @param Radius Radius (meters) to include in the search area, required if
#' `Latitude` and `Longitude` are specified.
#' @param Radius Radius (meters) to include in the search area. If `NULL`
#' (default) when `Lat` and `Lon` are supplied, a generic max of 50 kilometers
#' is used.
#' @inheritParams wmata_key
#' @examples
#' \dontrun{
#' bus_position("70", 38.8895, -77.0353, 2000)
#' bus_position("70", 38.8895, -77.0353)
#' }
#' @return Data frame containing bus position information.
#' @seealso <https://developer.wmata.com/docs/services/54763629281d83086473f231/operations/5476362a281d830c946a3d68>
Expand All @@ -53,17 +54,20 @@
#' @importFrom jsonlite fromJSON
#' @importFrom tibble add_column as_tibble
#' @export
bus_position <- function(RouteId = NULL, Lat = NULL, Lon = NULL, Radius = 1000,
bus_position <- function(RouteId = NULL, Lat = NULL, Lon = NULL, Radius = NULL,
api_key = wmata_key()) {
if (!is.null(Lat) && !is.null(Lon) && is.null(Radius)) {
Radius <- 50000
}
coord <- list(Lat = Lat, Lon = Lon, Radius = Radius)
dat <- wmata_api(
path = "Bus.svc/json/jBusPositions",
query = c(list(RouteId = RouteId), coord),
flatten = TRUE,
level = 1
)
if (length(dat) == 0) {
warning("no routes found within your radius, please expand")
if (no_data_now(dat)) {
message("No routes found within your radius, please expand")
return(empty_positions)
}
dat <- dat[, -8] # DirectionNum Deprecated
Expand All @@ -77,7 +81,7 @@ bus_position <- function(RouteId = NULL, Lat = NULL, Lon = NULL, Radius = 1000,
tibble::as_tibble(dat)
}

empty_positions <- data.frame(
empty_positions <- tibble::tibble(
VehicleID = character(),
Lat = double(),
Lon = double(),
Expand Down
2 changes: 1 addition & 1 deletion R/bus-routes.R
Expand Up @@ -8,7 +8,7 @@
#' \item{RouteID}{Unique identifier for a given route variant. Can be used in
#' various other bus-related methods.}
#' \item{Name}{Descriptive name of the route variant.}
#' \item{LineDescription}{Denotes the route variant's grouping lines are a
#' \item{LineDescription}{Denotes the route variant's grouping - lines are a
#' combination of routes which lie in the same corridor and which have
#' significant portions of their paths along the same roadways.}
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/bus-schedule.R
Expand Up @@ -55,7 +55,7 @@ bus_schedule <- function(RouteID, IncludingVariations = TRUE, Date = NULL,
if (!is.null(dat$Direction1)) {
dir1_stops <- dat$Direction1$StopTimes
dir1_stops <- rows_bind(dir1_stops, dat$Direction1$TripID, "TripID")
dat$Direction1 <- merge2(dat$Direction1[, -7], dir0_stops)
dat$Direction1 <- merge2(dat$Direction1[, -7], dir1_stops)
dat <- rbind(dat$Direction0, dat$Direction1)
} else {
dat <- dat$Direction0
Expand Down
4 changes: 2 additions & 2 deletions R/bus-stops.R
Expand Up @@ -46,8 +46,8 @@ bus_stops <- function(Lat = NULL, Lon = NULL, Radius = NULL,
level = 1,
api_key = api_key
)
if (length(dat) == 0) {
warning("No bus stops found, please expand your Radius")
if (no_data_now(dat)) {
message("No bus stops found, please expand your Radius")
return(empty_stops)
}
if (is.null(Lat) || is.null(Lon)) {
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Expand Up @@ -61,7 +61,7 @@
#' \item{RouteID}{Unique identifier for a given route variant. Can be used in
#' various other bus-related methods.}
#' \item{Name}{Descriptive name of the route variant.}
#' \item{LineDescription}{Denotes the route variant's grouping lines are a
#' \item{LineDescription}{Denotes the route variant's grouping - lines are a
#' combination of routes which lie in the same corridor and which have
#' significant portions of their paths along the same roadways.}
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/incidents-bus.R
Expand Up @@ -37,7 +37,7 @@ bus_incidents <- function(Route = NULL, api_key = wmata_key()) {
flatten = TRUE,
level = 1
)
if (length(dat) == 0 || nrow(dat) == 0) {
if (no_data_now(dat)) {
message("No bus incidents reported")
return(empty_bus_incident)
}
Expand Down
2 changes: 1 addition & 1 deletion R/incidents-elevator.R
Expand Up @@ -45,7 +45,7 @@ elevator_incidents <- function(StationCode = NULL, api_key = wmata_key()) {
level = 1,
api_key = api_key
)
if (length(dat) == 0) {
if (no_data_now(dat)) {
message("no elevator incidents reported")
return(empty_elevator)
}
Expand Down
5 changes: 1 addition & 4 deletions R/incidents-rail.R
Expand Up @@ -31,17 +31,14 @@ rail_incidents <- function(api_key = wmata_key()) {
level = 1,
api_key = api_key
)
if (length(dat) == 0) {
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?")
if (all(vapply(dat[[4]], length, double(1)) == 1)) {
dat[[4]] <- unlist(dat[[4]])
}
dat[[5]] <- api_time(dat[[5]])
tibble::as_tibble(dat)
}
Expand Down
2 changes: 1 addition & 1 deletion R/key.R
Expand Up @@ -61,7 +61,7 @@ wmata_validate <- function(api_key = wmata_key()) {
)
if (httr::http_error(val)) {
msg <- httr::content(val)
httr::stop_for_status(msg$statusCode, msg$message)
stop(msg$message, call. = FALSE)
} else {
TRUE
}
Expand Down
8 changes: 5 additions & 3 deletions R/metro.R → R/metro-package.R
Expand Up @@ -45,7 +45,9 @@
#' * Standard Routes: [standard_routes()]
#' * Track Circuits: [track_circuits()]
#'
#' @docType package
#' @name metro
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
#> NULL
4 changes: 2 additions & 2 deletions R/next-bus.R
Expand Up @@ -42,8 +42,8 @@ next_bus <- function(StopID, api_key = wmata_key()) {
flatten = TRUE,
api_key = api_key
)
if (length(dat$Predictions) == 0) {
warning("No busses arriving at this stop")
if (no_data_now(dat$Predictions)) {
message("No busses arriving at this stop")
return(empty_next_bus)
}
dat <- tibble::add_column(
Expand Down
4 changes: 2 additions & 2 deletions R/next-train.R
Expand Up @@ -64,8 +64,8 @@ next_train <- function(StationCodes = NULL, api_key = wmata_key()) {
level = 1,
api_key = api_key
)
if (length(dat) == 0) {
warning("No next trains arriving at this station")
if (no_data_now(dat)) {
message("No next trains arriving at this station")
return(empty_next_train)
}
dat$Min[dat$Min == "ARR"] <- 0L
Expand Down
4 changes: 2 additions & 2 deletions R/rail-entrance.R
Expand Up @@ -49,8 +49,8 @@ rail_entrance <- function(Lat = NULL, Lon = NULL, Radius = NULL,
level = 1,
api_key = api_key
)
if (length(dat) == 0) {
warning("no entrances found within your radius, please expand")
if (no_data_now(dat)) {
message("No entrances found within your radius, please expand")
return(empty_entrance)
}
dat <- dat[, -1] # Deprecated: ID
Expand Down
11 changes: 11 additions & 0 deletions R/utils.R
Expand Up @@ -31,3 +31,14 @@ rows_bind <- function(list, list_names, col_name = "rowname", ...) {
out
}
}

#' Check if data has length and rows
#'
#' @param x A data frame or list to check
#' @examples
#' no_data_now(data.frame())
#' no_data_now(data.frame(a = 1))
#' @export
no_data_now <- function(x) {
length(x) == 0 || (is.data.frame(x) & nrow(x) == 0)
}

0 comments on commit 73a0932

Please sign in to comment.