Learn R Programming

gtfstools

gtfstools offers a set of convenient tools for editing and analysing transit feeds in GTFS format. Feeds are read as a list of data.tables, allowing for easy and fast data manipulation. Many of this package’s features are based on functions from other packages, especially {tidytransit} and {gtfs2gps}.

Installation

Stable version:

install.packages("gtfstools")

Development version:

# either
install.packages("gtfstools", repos = "https://dhersz.r-universe.dev")

# or
# install.packages("remotes")
remotes::install_github("ipea/gtfstools")

This package requires a working installation of {sf}. Please check this link for more information on how to install it.

Usage

Please read gtfstools vignettes for more on the package usage:

  • Basic usage: reading, analysing, manipulating and writing feeds. Run vignette("gtfstools") or check it on the website (Introduction to gtfstools).
  • Filtering GTFS feeds. Run vignette("filtering", package = "gtfstools") or check it on the website (Filtering GTFS feeds).
  • Editing GTFS feeds. Run vignette("editing", package = "gtfstools") or check it on the website (Editing GTFS feeds).
  • Querying GTFS feeds. Run vignette("querying", package = "gtfstools") or check it on the website (Querying GTFS feeds).
  • Mapping GTFS feeds. Run vignette("mapping", package = "gtfstools") or check it on the website (Mapping GTFS feeds).
  • Validating GTFS feeds. Run vignette("validating", package = "gtfstools") or check it on the website (Validating GTFS feeds).
  • Checking the calendar overlap of GTFS feeds. Run vignette("calendar_overlap", package = "gtfstools") or check it on the website (Checking the calendar overlap of GTFS feeds).
  • Building transit network graphs. Run vignette("graphs", package = "gtfstools") or check it on the website (Building transit network graphs).

Related packages

  • {gtfs2gps}: Converting public transport data from GTFS format to GPS-like records
  • {gtfs2emis}: Estimating public transport emissions from GTFS data
  • {GTFShift}: Explore and Analyse GTFS with a Focus on Urban Mobility
  • {tidytransit}: Read, Validate, Analyze, and Map GTFS Feeds
  • {croquis}: Interactive way to create and edit GTFS feeds in R
  • {gtfsrealtime}: Read GTFS-Realtime Files into Data Frames
  • {gtfsrouter}: Routing with GTFS data
  • {r5r}: Rapid Realistic Routing with R5 in R

Acknowledgement

gtfstools is developed by a team at the Institute for Applied Economic Research (Ipea), Brazil.

Copy Link

Version

Install

install.packages('gtfstools')

Monthly Downloads

776

Version

2.0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Rafael H. M. Pereira

Last Published

November 5th, 2026

Functions in gtfstools (2.0.1)

convert_stops_to_sf

Convert stops table to simple feature object (deprecated)
convert_seconds_to_time

Convert seconds after midnight to time strings
convert_sf_to_shapes

Convert a simple feature object into a shapes table
combine_nearby_stops

Combine nearby stops
convert_stops_to_shapes

Convert stops into shapes
convert_shapes_to_sf

Convert shapes table to simple feature object (deprecated)
convert_time_to_seconds

Convert time fields to seconds after midnight
copy_gtfs_without_file

Make a GTFS copy without a given file
crop_gtfs

Crop a GTFS object to a spatial extent
empty_service_network

Create an empty transit network
download_validator

Download MobilityData's GTFS validator
filter_by_spatial_extent

Filter a GTFS object using a spatial extent
filter_by_service_id

Filter GTFS object by service_id
dates_to_periods

Collapse days into periods of consecutive days
filter_by_shape_id

Filter GTFS object by shape_id
filter_by_date

Filter GTFS object by date
filter_by_sf

Filter a GTFS object using a simple features object (defunct)
filter_by_agency_id

Filter GTFS object by agency_id
empty_trip_length

Create an empty output of get_trip_length()
copy_gtfs_diff_field_class

Make a GTFS copy with a field of a different class
date_to_integer

Convert a Date vector into an integer vector
convert_to_standard

Convert a gtfstools' GTFS into a standards-compliant GTFS
copy_gtfs_without_field

Make a GTFS copy without a given field from a given file
filter_by_route_id

Filter GTFS object by route_id
filter_by_route_type

Filter GTFS object by route_type (transport mode)
filter_by_period

Filter GTFS object by period
filter_by_weekday

Filter GTFS object by weekday
filter_by_trip_id

Filter GTFS object by trip_id
fix_gtfs

Fix common problems in GTFS feeds
find_stop_pairs_within

Find the pairs of stops within a distance of each other
first_departure_per_trip

Get the earliest departure of each trip
fix_overnight_frequencies

Fix the end times after midnight of frequencies
fix_overnight_times

Fix times after midnight written as early morning times
get_parent_station

Get parent stations recursively
get_route_frequency

Get route frequency
frequencies_to_stop_times

Convert frequencies to stop times
get_route_timetable

Get route timetable
get_service_days

Get the service days of a GTFS object and their number of trips
get_dwell_time

Get dwell time
get_shape_length

Get shape length
get_services_on_days

Get the services that run on the given days
get_frequencies_departures

Get the departures generated by frequencies entries
get_dates

Get service dates
get_service_period

Get the service days of a GTFS object
get_service_weights

Get the number of trips each service runs on a day
get_children_stops

Get children stops recursively
get_start_and_end_times

Get start and end times
get_shapes_geometry

Get the shapes table with spatial geometry
get_route_geometry

Get route geometry
get_trip_duration

Get trip duration
fix_overnight_in_call

Fix the times after midnight silently
fix_overnight_stop_times

Fix the times after midnight of stop_times
get_route_speed

Get route speed
get_trip_departures

Get the departure times of trips
get_stop_node_keys

Get the node of each stop
get_stop_distances

Get distances between stops
get_stop_times_patterns

Get stop times patterns
get_stop_frequency

Get stop frequency
get_stops

Get stops
get_stop_timetable

Get stop timetable
has_overnight_trips

Check whether a feed has trips with times after midnight to fix
has_shapes

Check whether a GTFS object has shapes linked to its trips
get_vmt

Get vehicle-miles travelled
gtfstools

gtfstools: General Transit Feed Specification (GTFS) Editing and Analysing Tools
get_active_services

Get active services
get_stops_geometry

Get the stops table with spatial geometry
get_calendar_overlap

Get calendar overlap
filter_by_stop_id

Filter GTFS object by stop_id
filter_by_time_of_day

Filter GTFS object by time of day
get_summary

Get a summary of a GTFS feed
interpolate_cropped_trips

Interpolate the times of cropped trips
get_trip_speed

Get trip speed
get_trip_segment_duration

Get trip segments' duration
locate_stops_along_shapes

Locate stops along their trips' shapes
map_deprecated_file

Map the deprecated file argument to method
paste_stop_names

Paste stop names
parse_dates

Parse dates given as Dates or strings
infer_trip_directions

Infer the direction of trips
integer_to_date

Convert an integer vector into a Date vector
get_vkt

Get vehicle-kilometres travelled
get_usable_shapes

Get the usable shapes of a shapes table
get_trip_geometry

Get trip geometry
set_dwell_time

Set dwell time
set_max_speed

Set trip maximum speed
report_deps_available

Check whether the report dependencies are available
merge_gtfs

Merge GTFS files
list_validator_versions

List MobilityData's GTFS validator versions
resolve_shapes_method

Fall back to the euclidean method when a GTFS object has no usable shapes
merge_service_intervals

Merge the overlapping calendar intervals of each service and weekday
locate_cropped_trip_cuts

Locate the cuts of the shapes of cropped trips
remove_duplicates

Remove duplicated entries
get_trip_length

Get trip length
interpolate_shape_dist_traveled

Interpolate the distances travelled along shapes
max_stop_pairs_without_warning

Maximum number of stop pairs without a warning
prepare_shape_points

Select and sort the shape points
replace_stop_ids

Replace stop_ids
prepare_trip_stops

Select and prepare the stop_times of the relevant trips
replace_cropped_shapes

Replace the shapes of cropped trips by their cuts
match_stop_times_rows

Match stop_times entries by trip and stop sequence
set_min_dwell_time

Set a minimum dwell time
set_min_speed

Set trip minimum speed
shift_cropped_frequencies

Shift the frequencies of cropped trips
warn_invalid_ids

Warn about ids missing from a table, with cli
stop_id_references

Fields that refer to stop_ids, by file
set_route_frequency

Set route frequency
set_route_speed

Set route average speed
read_gtfs

Read GTFS files
tables_not_data_table

Which tables of a GTFS object are data.frames but not data.tables
interpolate_stop_times

Interpolate missing stop times
sum_or_na

Sum a vector, or return NA if it has no values
route_type_ids

Get the route_ids of the given route_types
is_blank_time

Check which time strings are blank
summarise_distribution

Summarise a distribution
refresh_secs_columns

Refresh the *_secs columns of a table after its time strings changed
warn_missing_ids

Warn about ids missing from a table
validate_gtfs

Validate GTFS feed
remove_unused_ids

Remove unused ids
set_trip_speed

Set trip average speed
time_of_day_window

Convert a time of day to seconds and check its order
warn_times_not_interpolated

Warn about stop times that couldn't be interpolated
shape_point_distances

Distance from each shape point to the previous one
time_secs

Get the times of a column in seconds after midnight
write_gtfs

Write GTFS files
write_summary_report

Write and render the report of get_summary()
warn_trips_without_shape

Warn about trips not linked to a usable shape
seconds_to_string

Convert seconds after midnight to time string
summarise_route_frequency

Calculate the route headways of a feed on its busiest day
stop_times_to_frequencies

Convert stop times to frequencies
string_to_seconds

Convert time string to seconds after midnight
summarise_services

Summarise the calendar of the services of a feed
build_graph

Build a transit network graph
as_dt_gtfs

Coerce lists and GTFS objects from other packages into gtfstools-compatible GTFS objects
assert_trip_stops_fields

Assert the stop_times and stops fields needed to work with trip stops
assert_shapes_fields

Assert the shapes (and trips) fields needed to work with shapes
cluster_stop_nodes

Cluster stop nodes by distance
calendar_service_intervals

Get the weekday intervals of the calendar entries
calculate_vkt

Calculate the vehicle-kilometres travelled by groups of trips
build_linestrings

Build linestrings from sequences of points
check_deprecated_sort_sequence

Raise the deprecation condition of the sort_sequence argument
build_service_network

Build the nodes and links of a transit network
convert_from_standard

Convert a standards-compliant GTFS into a gtfstools' GTFS
check_stop_pair_count

Check the number of pairs of stops before comparing them
build_timetable

Build a timetable
build_shape_cuts

Build the geometries of parts of shapes