diff --git a/DESCRIPTION b/DESCRIPTION index 378946b0..256aac7b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,10 @@ Authors@R: c( person("Alexandra", "Kapp", role = c("ctb")), person("Kearey", "Smith", role = c("ctb")), person("Dave", "Vautin", role = c("ctb")), - person("Kyle", "Walker", role = c("ctb")) + person("Kyle", "Walker", role = c("ctb")), + person("Davis", "Vaughan", role = c("ctb")), + person("Ryan", "Rymarczyk", role = c("ctb")), + person("Kirill", "Müller", role = c("ctb")) ) Description: Read General Transit Feed Specification (GTFS) zipfiles into a list of R dataframes. Perform validation of the data structure against the specification. Analyze the headways and frequencies at routes and stops. Create maps and perform spatial analysis on the routes and stops. Please see the GTFS documentation here for more detail: . License: GPL diff --git a/R/spatial.R b/R/spatial.R index e7253e1c..ce3ed9df 100644 --- a/R/spatial.R +++ b/R/spatial.R @@ -36,7 +36,7 @@ gtfs_as_sf <- function(gtfs_obj, skip_shapes = FALSE, crs = NULL, quiet = TRUE) #' lon/lat coordinates #' @return an sf dataframe for gtfs routes with a point column #' -#' @seealso code{\link{gtfs_as_sf}} +#' @seealso \code{\link{gtfs_as_sf}} #' @export #' @examples #' data(gtfs_duke) diff --git a/man/stops_as_sf.Rd b/man/stops_as_sf.Rd index 6ca3a349..3d4b3dc2 100644 --- a/man/stops_as_sf.Rd +++ b/man/stops_as_sf.Rd @@ -25,5 +25,5 @@ some_stops_sf <- stops_as_sf(some_stops) plot(some_stops_sf) } \seealso{ -code{\link{gtfs_as_sf}} +\code{\link{gtfs_as_sf}} } diff --git a/tests/testthat.R b/tests/testthat.R index d3a15ea1..c8d45983 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,4 @@ +data.table::setDTthreads(2) library(testthat) library(tidytransit) diff --git a/tests/testthat/test-as_tidygtfs.R b/tests/testthat/test-as_tidygtfs.R index 41e8330d..814d874b 100644 --- a/tests/testthat/test-as_tidygtfs.R +++ b/tests/testthat/test-as_tidygtfs.R @@ -13,7 +13,7 @@ test_that("as_tidygtfs w/ gtfstools", { expect_equal(dt_gtfs.tidygtfs[[table_name]], tidygtfs[[table_name]]) } - expect_is(dt_gtfs.tidygtfs, "tidygtfs") + expect_s3_class(dt_gtfs.tidygtfs, "tidygtfs") }) test_that("as_tidygtfs w/ list", { @@ -28,7 +28,7 @@ test_that("as_tidygtfs w/ list", { gtfs_list.tidygtfs = as_tidygtfs(gtfs_list) expect_equal(gtfs_list.tidygtfs, tidygtfs) - expect_is(gtfs_list.tidygtfs, "tidygtfs") + expect_s3_class(gtfs_list.tidygtfs, "tidygtfs") }) test_that("as_tidygtfs w/ gtfs", { @@ -38,7 +38,7 @@ test_that("as_tidygtfs w/ gtfs", { gtfs.tidygtfs = as_tidygtfs(gtfs) expect_equal(gtfs.tidygtfs, tidygtfs) - expect_is(gtfs.tidygtfs, "tidygtfs") + expect_s3_class(gtfs.tidygtfs, "tidygtfs") }) test_that("as_tidygtfs w/ tidygtfs", { @@ -49,5 +49,5 @@ test_that("as_tidygtfs w/ tidygtfs", { x2 = as_tidygtfs(x1) expect_true(all(x2$.$dates_services$service_id == "WEEK")) - expect_is(x2, "tidygtfs") + expect_s3_class(x2, "tidygtfs") }) diff --git a/tests/testthat/test-headways.R b/tests/testthat/test-frequencies.R similarity index 97% rename from tests/testthat/test-headways.R rename to tests/testthat/test-frequencies.R index 374a7a83..936effe0 100644 --- a/tests/testthat/test-headways.R +++ b/tests/testthat/test-frequencies.R @@ -1,5 +1,3 @@ -context("Frequencies are calculated correctly") - # TODO rewrite with synthesized sample data test_that("Stop frequencies (headways) for included data are as expected", { expect_equal(nrow(get_stop_frequency(gtfs_duke, by_route = FALSE)), 47) diff --git a/tests/testthat/test-raptor.R b/tests/testthat/test-raptor.R index 7f036bd3..a787eb2b 100644 --- a/tests/testthat/test-raptor.R +++ b/tests/testthat/test-raptor.R @@ -1,5 +1,3 @@ -context("raptor travel time routing") - local_gtfs_path <- system.file("extdata", "routing.zip", package = "tidytransit") gtfs_routing <- read_gtfs(local_gtfs_path) test_from_stop_ids <- c("stop1a", "stop1b") diff --git a/tests/testthat/test-read-gtfs.R b/tests/testthat/test-read-gtfs.R index 01d6fbc7..d8d3f10c 100644 --- a/tests/testthat/test-read-gtfs.R +++ b/tests/testthat/test-read-gtfs.R @@ -1,46 +1,58 @@ -context("Import and Validation") +g_routing_path <- system.file("extdata", "routing.zip", + package = "tidytransit") -gtfs_example_url <- - "https://github.com/r-transit/tidytransit/raw/master/inst/extdata/sample-feed-fixed.zip" -local_gtfs_path <- system.file("extdata", - "google_transit_nyc_subway.zip", - package = "tidytransit") +test_that("read_gtfs() imports a local file to a list of + dataframes and doesnt delete the source file", { -test_that("read_gtfs() imports a local file to a - list of dataframes and doesnt - delete the source file", { - gtfs_obj <- read_gtfs(local_gtfs_path) + gtfs_obj = read_gtfs(g_routing_path) - expect_is(gtfs_obj, "gtfs") - file.exists(local_gtfs_path) + expect_type(gtfs_obj, "list") + expect_s3_class(gtfs_obj, "tidygtfs") + expect_s3_class(gtfs_obj, "gtfs") + expect_true(file.exists(g_routing_path)) +}) + +test_that("reading a real feed", { + skip_on_cran() + g_nyc_path = system.file("extdata", "google_transit_nyc_subway.zip", + package = "tidytransit") + gtfs_obj = read_gtfs(g_nyc_path) + + expect_type(gtfs_obj, "list") + expect_s3_class(gtfs_obj, "tidygtfs") + expect_s3_class(gtfs_obj, "gtfs") }) test_that("loud read_gtfs", { - expect_is( - read_gtfs(local_gtfs_path, quiet = FALSE), + expect_s3_class( + read_gtfs(g_routing_path, quiet = FALSE), "tidygtfs") }) test_that("gtfsio arguments", { - expect_is( - read_gtfs(local_gtfs_path, encoding = "UTF-8"), + skip_on_cran() + expect_s3_class( + read_gtfs(g_routing_path, encoding = "UTF-8"), "tidygtfs" ) }) - test_that("tidygtfs class inheritance list", { expect_equal( - class(read_gtfs(local_gtfs_path)), + class(read_gtfs(g_routing_path)), c("tidygtfs", "gtfs", "list") ) }) test_that("the read_gtfs function works with urls", { skip_on_cran() + gtfs_example_url <- + "https://github.com/r-transit/tidytransit/raw/master/inst/extdata/sample-feed-fixed.zip" + x <- read_gtfs(gtfs_example_url, quiet=TRUE) - expect_is(x, "gtfs") # should return 'list' object - expect_is(x, "tidygtfs") + expect_type(x, "list") + expect_s3_class(x, "gtfs") + expect_s3_class(x, "tidygtfs") }) test_that("the read_gtfs function fails gracefully on bad urls", { @@ -60,7 +72,7 @@ test_that("Files with BOM can be read", { "sample-feed-bom.zip", package = "tidytransit") g <- read_gtfs(bom_path) - expect_is(g, "tidygtfs") + expect_s3_class(g, "tidygtfs") }) test_that("Feed with additional data can be read", { @@ -121,6 +133,6 @@ test_that("non-unique stop_ids", { g2 = suppressWarnings(read_gtfs(tmppath)) - expect_is(g2, "gtfs") + expect_s3_class(g2, "gtfs") expect_false(inherits(g2, "tidygtfs")) }) diff --git a/tests/testthat/test-service.R b/tests/testthat/test-service.R index 984dd403..f88834e0 100644 --- a/tests/testthat/test-service.R +++ b/tests/testthat/test-service.R @@ -1,5 +1,3 @@ -context("Servicepattern") - gpath <- system.file("extdata", "routing.zip", package = "tidytransit") test_that("set_servicepattern", { diff --git a/tests/testthat/test-spatial.R b/tests/testthat/test-spatial.R index e69ce9c4..9e9b4487 100644 --- a/tests/testthat/test-spatial.R +++ b/tests/testthat/test-spatial.R @@ -1,14 +1,13 @@ -context("Converting to sf objects") library(sf) test_that("convert gtfs stops and shapes to sf data frames", { - expect_is(stops_as_sf(gtfs_duke$stops), "sf") + expect_s3_class(stops_as_sf(gtfs_duke$stops), "sf") shapes_sf = shapes_as_sf(gtfs_duke$shapes) - expect_is(shapes_sf, "sf") + expect_s3_class(shapes_sf, "sf") expect_equal(nrow(shapes_sf), length(unique(gtfs_duke$shapes$shape_id))) duke_sf <- gtfs_as_sf(gtfs_duke) - expect_is(duke_sf$shapes, "sf") - expect_is(duke_sf$stops, "sf") + expect_s3_class(duke_sf$shapes, "sf") + expect_s3_class(duke_sf$stops, "sf") duke_sf2 = gtfs_as_sf(duke_sf) expect_equal(duke_sf2, duke_sf) }) @@ -126,7 +125,7 @@ test_that("geodist", { xlon = c(8.4590, 8.4714) xlat = c(47.1812, 47.1824) dist1 = geodist_list(xlon, xlat) - expect_is(dist1, "list") + expect_type(dist1, "list") expect_equal(length(dist1), 1) x_sf = sf::st_as_sf(data.frame(lon = xlon, lat = xlat), coords = c("lon", "lat"), crs = 4326) @@ -139,13 +138,14 @@ test_that("geodist", { test_that("stop_group_distances", { x = stop_group_distances(stopdist_df) expect_equal(colnames(x), c("stop_name", "distances", "n_stop_ids", "dist_mean", "dist_median", "dist_max")) - expect_is(x$distances[1][[1]], "matrix") + expect_true(is.matrix(x$distances[1][[1]])) expect_equal(x$n_stop_ids, c(3,2)) }) -g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")) - test_that("stop_group_distances real feed", { + skip_on_cran() + g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")) + x1 = stop_group_distances(g_nyc$stops) g_nyc_sf = gtfs_as_sf(g_nyc) @@ -163,6 +163,9 @@ test_that("stop_group_distances real feed", { }) test_that("stops cluster", { + skip_on_cran() + + g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")) g_nyc2 <- filter_feed_by_area(g_nyc, c(-74.0144, 40.7402, -73.9581, 40.7696)) x1 = cluster_stops(g_nyc2$stops) @@ -179,5 +182,5 @@ test_that("stops cluster", { # piping gtfs_obj g_nyc2 = cluster_stops(g_nyc2) - expect_is(g_nyc2, "tidygtfs") + expect_s3_class(g_nyc2, "tidygtfs") }) diff --git a/tests/testthat/test-time.R b/tests/testthat/test-time.R index 33c02d71..8dab5e1d 100644 --- a/tests/testthat/test-time.R +++ b/tests/testthat/test-time.R @@ -1,5 +1,3 @@ -context("Time manipulation") - create_empty_gtfs_obj <- function() { g <- list(agency = data.frame()) gtfsio::new_gtfs(g) @@ -17,14 +15,14 @@ test_that("convert_times_to_hms() works with valid data", { gtest <- convert_times_to_hms(gtest) - expect_is(gtest$stop_times$arrival_time, "hms") - expect_is(gtest$stop_times$departure_time, "hms") + expect_s3_class(gtest$stop_times$arrival_time, "hms") + expect_s3_class(gtest$stop_times$departure_time, "hms") expect_false(is.na(gtest$stop_times$arrival_time[3])) expect_equal(gtest$stop_times$departure_time[3], hms::hms(26 * 3600 + 10 * 60 + 30)) - expect_is(gtest$frequencies$start_time, "hms") - expect_is(gtest$frequencies$end_time, "hms") + expect_s3_class(gtest$frequencies$start_time, "hms") + expect_s3_class(gtest$frequencies$end_time, "hms") }) test_that("set_dates_services() uses the right dates", { @@ -110,7 +108,7 @@ test_that("set_dates_services() works with additions and exceptions", { test_that("parse dates", { x = "20180429" y = parse_gtfsio_date(x) - expect_is(y, "Date") + expect_s3_class(y, "Date") z = date_as_gtfsio_char(y) expect_equal(x, z) }) diff --git a/tests/testthat/test-travel_times.R b/tests/testthat/test-travel_times.R index b145715b..2e6f41b1 100644 --- a/tests/testthat/test-travel_times.R +++ b/tests/testthat/test-travel_times.R @@ -1,5 +1,3 @@ -context("travel_times routing") - local_gtfs_path <- system.file("extdata", "routing.zip", package = "tidytransit") gtfs_routing <- read_gtfs(local_gtfs_path) test_from_stop_ids <- c("stop1a", "stop1b") @@ -159,6 +157,7 @@ test_that("feed without transfers", { }) test_that("nyc feed", { + skip_on_cran() nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit") nyc <- read_gtfs(nyc_path) @@ -175,5 +174,5 @@ test_that("nyc feed", { tts <- travel_times(nyc_st, "34 St - Herald Sq (D17)", return_coords = TRUE, stop_dist_check = FALSE) - expect_is(tts, "data.frame") + expect_s3_class(tts, "data.frame") }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 6b633ccf..1b0ae9ac 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,5 +1,3 @@ -context("Utils") - test_that("summary.tidygtfs", { gpath <- system.file("extdata", "routing.zip", package = "tidytransit") g1 = read_gtfs(gpath) @@ -81,8 +79,8 @@ test_that("filter_feed with shapes", { }) test_that("filter_feed_by_date", { - g0 = read_gtfs(system.file("extdata", - "google_transit_nyc_subway.zip", + skip_on_cran() + g0 = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")) g1 = filter_feed_by_date(g0, "2018-06-28") g2 = filter_feed_by_date(g0, "2018-10-30") @@ -91,12 +89,11 @@ test_that("filter_feed_by_date", { expect_lt(nrow(g1$stops), nrow(g0$stops)) expect_lt(nrow(g2$stops), nrow(g0$stops)) - expect_is(g1$stop_times, "tbl_df") - expect_is(g2$stop_times, "tbl_df") + expect_s3_class(g1$stop_times, "tbl_df") + expect_s3_class(g2$stop_times, "tbl_df") }) - -test_that("gtfs_meta", { # empty test +test_that("gtfs_meta", { expect_equal(gtfs_meta, get_gtfs_meta()) }) diff --git a/tests/testthat/test-validate.R b/tests/testthat/test-validate.R index dd82205c..e1e83012 100644 --- a/tests/testthat/test-validate.R +++ b/tests/testthat/test-validate.R @@ -21,14 +21,14 @@ test_that("warning for duplicated primary key", { # within as_tidygtfs g2 = expect_warning(as_tidygtfs(g1), "Duplicated ids found in: routes, stops") - expect_is(g2, "list") + expect_type(g2, "list") g3 = g2 g3$stops$stop_id[1] <- "stop1" g3$routes$route_id[1] <- "lineA" g4 = as_tidygtfs(g3) - expect_is(g4, "tidygtfs") + expect_s3_class(g4, "tidygtfs") }) test_that("validate non gtfs object", { diff --git a/tests/testthat/test-write-gtfs.R b/tests/testthat/test-write-gtfs.R index 6aaa9d4d..4adaecb4 100644 --- a/tests/testthat/test-write-gtfs.R +++ b/tests/testthat/test-write-gtfs.R @@ -1,5 +1,3 @@ -context("Export") - test_that("write_gtfs creates the same feed as read by read_gtfs", { skip_on_cran() path1 <- system.file("extdata", "sample-feed-fixed.zip", package = "tidytransit")