This function reads GTFS text files from a local or remote zip file. It also validates the files against the GTFS specification by file, requirement status, and column name The data are returned as a list of dataframes and a validation object, which contains details on whether all required files were found, and which required and optional columns are present.

import_gtfs(path, local = FALSE, quiet = FALSE)

Arguments

path

Character. url link to zip file OR path to local zip file. if to local path, then option local must be set to TRUE.

local

Boolean. If the paths are searching locally or not. Default is FALSE (that is, urls).

quiet

Boolean. Whether to see file download progress and files extract. FALSE by default.

Value

Dataframes of GTFS data.

Examples

library(dplyr)
#> #> Attaching package: ‘dplyr’
#> The following object is masked from ‘package:testthat’: #> #> matches
#> The following objects are masked from ‘package:stats’: #> #> filter, lag
#> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union
u1 <- "https://github.com/r-transit/tidytransit/raw/master/inst/extdata/sample-feed-fixed.zip" sample_gtfs <- import_gtfs(u1)
#> Warning: 'import_gtfs' is deprecated. #> Use 'read_gtfs' instead. #> See help("Deprecated")
#> Unzipped the following files to directory '/var/folders/45/8fqzt7r535s1hjlmfc63l_fr0000gp/T//Rtmp96BQhE'...
#> [1] "agency.txt" "calendar_dates.txt" "calendar.txt" #> [4] "fare_attributes.txt" "fare_rules.txt" "file1b15f5cc8cd.zip" #> [7] "frequencies.txt" "routes.txt" "shapes.txt" #> [10] "stop_times.txt" "stops.txt" "transfers.txt" #> [13] "trips.txt"
#> Reading files in feed...
#> Reading agency
#> Reading calendar_dates
#> Reading calendar
#> Reading fare_attributes
#> Reading fare_rules
#> Reading frequencies
#> Reading routes
#> Reading shapes
#> Reading stop_times
#> Reading stops
#> Reading trips
#> Reading files in feed... done.
#> Valid gtfs data structure.
#> Reading gtfs feed completed. #>
attach(sample_gtfs) #list routes by the number of stops they have routes %>% inner_join(trips, by="route_id") %>% inner_join(stop_times) %>% inner_join(stops, by="stop_id") %>% group_by(route_long_name) %>% summarise(stop_count=n_distinct(stop_id)) %>% arrange(desc(stop_count))
#> Joining, by = "trip_id"
#> # A tibble: 5 x 2 #> route_long_name stop_count #> <chr> <int> #> 1 City 5 #> 2 Airport - Amargosa Valley 2 #> 3 Airport - Bullfrog 2 #> 4 Bullfrog - Furnace Creek Resort 2 #> 5 Stagecoach - Airport Shuttle 2