Function to calculate the shortest travel times from a stop (given by stop_name) to all other stop_names of a feed. filtered_stop_times needs to be created before with filter_stop_times() or filter_feed_by_date().

  time_range = 3600,
  arrival = FALSE,
  max_transfers = NULL,
  max_departure_time = NULL,
  return_coords = FALSE,
  return_DT = FALSE,
  stop_dist_check = 300



stop_times data.table (with transfers and stops tables as attributes) created with filter_stop_times() where the departure or arrival time has been set. Alternatively, a filtered feed created by filter_feed_by_date() can be used.


Stop name for which travel times should be calculated. A vector with multiple names is accepted.


All departures within this range in seconds after the first departure of filtered_stop_times are considered for journeys. If arrival is TRUE, all journeys arriving within time range before the latest arrival of filtered_stop_times are considered.


If FALSE (default), all journeys start from stop_name. If TRUE, all journeys end at stop_name.


The maximimum number of transfers


Either set this parameter or time_range. Only departures before max_departure_time are used. Accepts "HH:MM:SS" or seconds as a numerical value. Unused if arrival is TRUE.


Returns stop coordinates as columms. Default is FALSE.


travel_times() returns a data.table if TRUE. Default is FALSE which returns a tibble/tbl_df.


stop_names are not structured identifiers like stop_ids or parent_stations, so it's possible that stops with the same name are far apart. travel_times() errors if the distance among stop_ids with the same name is above this threshold (in meters). Use FALSE to turn check off. However, it is recommended to either use raptor() or fix the feed (see cluster_stops()).


A table with travel times to/from all stops reachable by stop_name and their corresponding journey departure and arrival times.


This function allows easier access to raptor() by using stop names instead of ids and returning shortest travel times by default.

Note however that stop_name might not be a suitable identifier for a feed. It is possible that multiple stops have the same name while not being related or geographically close to each other. stop_group_distances() and cluster_stops() can help identify and fix issues with stop_names.


# \donttest{
nyc_path <- system.file("extdata", "", package = "tidytransit")
nyc <- read_gtfs(nyc_path)

# stop_names in this feed are not restricted to an area, create clusters of stops to fix
nyc <- cluster_stops(nyc, group_col = "stop_name", cluster_colname = "stop_name")

# Use journeys departing after 7 AM with arrival time before 9 AM on 26th June
stop_times <- filter_stop_times(nyc, "2018-06-26", 7*3600, 9*3600)

tts <- travel_times(stop_times, "34 St - Herald Sq", return_coords = TRUE)
tts <- tts %>% filter(travel_time <= 3600)

# travel time to Queensboro Plaza is 810 seconds, 13:30 minutes
tts %>% filter(to_stop_name == "Queensboro Plaza") %>% pull(travel_time) %>% hms::hms()
#> 00:13:30

# plot a simple map showing travel times to all reachable stops
# this can be expanded to isochron maps
ggplot(tts) + geom_point(aes(x=to_stop_lon, y=to_stop_lat, color = travel_time))

# }