Skip to content
Package for obtaining, validating, viewing, and storing GTFS (transit) data
Branch: master
Clone or download
dantonnoriega Update DESCRIPTION
removed tidytransit
Latest commit 78e9500 Sep 19, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
R Update convert-gtfs.R Sep 19, 2018
data add mock gtfs data Jul 15, 2018
docs new package down render. added here package. moved data to data-raw. Jun 3, 2018
man add mock gtfs data Jul 15, 2018
vignettes new package down render. added here package. moved data to data-raw. Jun 3, 2018
.travis.yml added opensci package text files and updated readme Jun 23, 2016

Build Status


gtfsr is an R package for easily importing, validating, and mapping transit data that follows the General Transit Feed Specification (GTFS) format.

The gtfsr package provides functions for converting files following the GTFS format into a single gtfs data objects. A gtfs object can then be validated for proper data formatting (i.e. if the source data is properly structured and formatted as a GTFS feed) or have any spatial data for stops and routes mapped using leaflet. The gtfsr package also provides API wrappers for the popular public GTFS feed sharing site TransitFeeds, allowing users quick, easy access to hundreds of GTFS feeds from within R.


You can install this package from GitHub using the devtools package:

if (!require(devtools)) {

If you have already installed gtfsr, you can get the latest version by running


If you’d like to build the accompanying vignette, then run

devtools::install_github('ropensci/gtfsr', build_vignettes = TRUE)

Example Usage


# set the API key
# set_api_key() # uncomment to set api key

# get the feedlist dataframe and filter out NYC subway
feedlist_df <- get_feedlist() %>%
  filter(grepl('NYC Subway GTFS', t, TRUE))

# import NYC gtfs feed by sending the url to `import_gtfs`
NYC <- import_gtfs(feedlist_df$url_d)
#> [1] "agency.txt"         "calendar_dates.txt" "calendar.txt"      
#> [4] "routes.txt"         "shapes.txt"         "stop_times.txt"    
#> [7] "stops.txt"          "transfers.txt"      "trips.txt"

# get line (routes) A and B
routes <- NYC[['routes_df']] %>%
  slice(which(grepl('a|b', route_id, %>%

# take the NYC `gtfs` object and map routes. includes stops by default.
NYC %>% map_gtfs(route_ids = routes)

# gtfs will plot ALL shapes for a given route_ids. These can be reduced using the `service_ids` option.
ids <- NYC$trips_df %>%
  select(route_id, service_id, shape_id) %>%
  distinct() %>%
  filter(route_id %in% routes)
ids %>% head(5) # see all unique combos of ids
#> # A tibble: 5 x 3
#>   route_id service_id   shape_id
#>   <chr>    <chr>        <chr>   
#> 1 A        B20171105WKD A..N43R 
#> 2 A        B20171105WKD A..S43R 
#> 3 A        B20171105WKD A..N85R 
#> 4 A        B20171105WKD A..N54R 
#> 5 A        B20171105WKD A..N65R

# lets map just the the first row
route_ids <- ids$route_id[1]
service_ids <- ids$service_id[1]
shape_ids <- ids$shape_id[1]

# lets map the specific data with some other options enabled.
NYC %>%
  map_gtfs(route_ids = route_ids,
    service_ids = service_ids,
    shape_ids = shape_ids,
    route_colors = 'green', # set the route color
    stop_details = TRUE, # get more stop details on click
    route_opacity = .5) # change the route opacity


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.