Package {gtfsrealtime}


Title: Read GTFS-Realtime Files into Data Frames
Version: 0.2.1
Description: GTFS-realtime is a format transit agencies use to provide current vehicle positions, predicted arrival times, and service alerts. This package provides efficient functions to read this format into data frames. It can be used to retrieve current data or to process archived data.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Config/rextendr/version: 0.4.2
SystemRequirements: Cargo (Rust's package manager), rustc >= 1.88.0, xz
Depends: R (≥ 4.2)
Imports: cli, sf
Suggests: knitr, rmarkdown, ggplot2, data.table, purrr, gifski, lubridate, dplyr, tidyr, testthat (≥ 3.3.0), jsonlite, tidyselect, tibble, stringr
BugReports: https://github.com/mattwigway/gtfsrealtime-r/issues
VignetteBuilder: knitr
URL: http://projects.indicatrix.org/gtfsrealtime-r/
Config/testthat/edition: 3
NeedsCompilation: yes
Packaged: 2026-05-27 13:49:34 UTC; runner
Author: Matthew Bhagat-Conway ORCID iD [aut, cre, cph], Matthew Palm ORCID iD [ctb, cph], The GTFS-realtime authors and the authors of bundled Rust crates [ctb, cph] (See inst/AUTHORS.md for information on bundled dependencies and their licensing and copyright status.)
Maintainer: Matthew Bhagat-Conway <mwbc@unc.edu>
Repository: CRAN
Date/Publication: 2026-06-12 19:30:08 UTC

Read GTFS-realtime alerts

Description

This function reads GTFS realtime alerts. Alerts are hierarchical: a single alert can have multiple applicability periods, multiple affected entities, and translations to multiple languages. This function flattens all of that to a tabular format, with one row for every combination of applicability, entity, and language. All rows from a single alert can be identified through a common id. This is true even if there are duplicate IDs in the feed; they will be deduplicated by adding _duplicated_1, _duplicated_2, etc.

Usage

read_gtfsrt_alerts(filename, timezone, label_values = TRUE)

Arguments

filename

filename to read. Can be uncompressed or compressed with gzip or bzip2, or can be a ZIP file containing multiple feeds (e.g., all alerts for a whole day). Can also be an http:// or https:// URL (ZIP files are not supported when reading from a URL, but gzip and bzip2 are).

timezone

timezone of feed, in Olson format. Times in GTFS-realtime are stored as Unix time in UTC; this option will convert to local times. If you want to read times in UTC, specify "Etc/UTC".

label_values

should enum types in GTFS-realtime (i.e. categorical variables) be converted to factors with their English labels. If false, they will be left as numeric codes. Default true.

Details

Alerts are intended to capture widespread or long-term disruptions or changes. Trip updates (see read_gtfsrt_trip_updates()) are better suited to providing information about day-to-day delays and cancellations to specific trips.

Typically, GTFS-realtime feeds will contain only a single type of entity, but if there are multiple types of entities in a single feed, this function will read only the alerts.

Value

A data frame with one row for every combination of alert, applicability period, affected entity, and language. One alert potentially becomes many rows. The data frame has the following columns. Many of these descriptions come verbatim or nearly so from the GTFS-realtime specification. Path refers to where in the original GTFS-realtime Alert data structure each column comes from.

Examples

# This will read an alerts feed included with gtfsrealtime. Replace with
# the path to your own file if desired.
file = system.file("nyc-service-alerts.pb.bz2", package = "gtfsrealtime")

# Need to specify timezone so timestamps will be in local time.
read_gtfsrt_alerts(file, "America/New_York")

Read GTFS-realtime vehicle positions into a data frame.

Description

Reads vehicle position data from a GTFS-realtime feed into a data.frame with one row per position update. GTFS-realtime timestamps are represented in Unix time; a timezone must be specified to convert these to time-zone-aware R date-time objects (i.e. POSIXct).

Usage

read_gtfsrt_positions(filename, timezone, as_sf = FALSE, label_values = TRUE)

Arguments

filename

filename to read. Can be uncompressed or compressed with gzip or bzip2, or can be a ZIP file containing multiple feeds (e.g., all positions for a whole day). Can also be an http:// or https:// URL (ZIP files are not supported when reading from a URL, but gzip and bzip2 are).

timezone

timezone of feed, in Olson format. Times in GTFS-realtime are stored as Unix time in UTC; this option will convert to local times. If you want to read times in UTC, specify "Etc/UTC"

as_sf

return an sf (spatial) object rather than a data frame.

label_values

should enum types in GTFS-realtime (i.e. categorical variables) be converted to factors with their English labels. If false, they will be left as numeric codes? Default TRUE

Details

Typically, GTFS-realtime feeds will contain only a single type of entity, but if there are multiple types of entities in a single feed, this function will read only the vehicle positions. Each vehicle position will become a single row in the data frame.

Value

Data frame containing vehicle position data. The data frame will have the following columns. Note that most of these columns can contain NAs (and in most feeds, many will be entirely NA). GTFS-realtime is a hierarchical format that is converted to a flat format for use in R; the paths refer to where each column comes from within the GTFS-realtime VehiclePosition data structure. Each column is reported below with its definition, many of which come verbatim from the GTFS-realtime specification

Examples

# This will read a positions feed included with gtfsrealtime. Replace with
# the path to your own file if desired.
file = system.file("nyc-vehicle-positions.pb.bz2", package = "gtfsrealtime")

# Need to specify timezone so timestamps will be in local time.
read_gtfsrt_positions(file, "America/New_York")

Read GTFS-realtime trip updates

Description

This reads GTFS-realtime trip updates into a data frame, and flattens the hierarchical structure.

Usage

read_gtfsrt_trip_updates(filename, timezone, label_values = TRUE)

Arguments

filename

filename to read. Can be uncompressed or compressed with gzip or bzip2, or can be a ZIP file containing multiple feeds (e.g., all trip updates for a whole day). Can also be an http:// or https:// URL (ZIP files are not supported when reading from a URL, but gzip and bzip2 are).

timezone

timezone of feed, in Olson format. Times in GTFS-realtime are stored as Unix time in UTC; this option will convert to local times. If you want to read times in UTC, specify "Etc/UTC"

label_values

should enum types in GTFS-realtime (i.e. categorical variables) be converted to factors with their English labels. If false, they will be left as numeric codes. Default true.

Details

Trip updates can contain many stop time updates for different stops along a trip. These will be flattened to one row per stop time update, with fields of the trip update that apply to all stop time updates duplicated. You can figure out which rows came from a single trip update by looking at for common values in the id column. Rows which share an id are guaranteed to have come from a single trip update, even if there are duplicate IDs in the GTFS-realtime data. If there are duplicate IDs, they will be deduplicated by appending _duplicated_1, _duplicated_2, etc., and a warning will be issued. If a trip update contains no stop time updates, it will result in a single row in the output.

Value

a data frame with a row for each stop time update (and a minimum of one row for each trip update when there are no stop time updates. The data frame has the following columns, with descriptions based on or copied directly from the GTFS-realtime specification. The path of each column identifies where in the GTFS-realtime TripUpdate object the field's value is taken from.

Note that

Examples

# This will read an updates feed included with gtfsrealtime. Replace with
# the path to your own file if desired.
file = system.file("nyc-trip-updates.pb.bz2", package = "gtfsrealtime")

# Need to specify timezone so timestamps will be in local time.
read_gtfsrt_trip_updates(file, "America/New_York")

mirror server hosted at Truenetwork, Russian Federation.