Skip to contents

{gtfsrealtime}

R-CMD-check

maintenance-status: actively-developed

Fast library to read GTFS-realtime files into R data frames.

Installation

The package is installable from mattwigway.r-universe.dev. Run the following at your R prompt:

install.packages('gtfsrealtime', repos = c('https://mattwigway.r-universe.dev', 'https://cloud.r-project.org'))

It requires the current or previous release of R (currently 4.6 or 4.5); older versions are likely to work as well but will require building code from scratch which requires a Rust development environment. If you get errors about rustc not being found, you likely need to upgrade your version of R.

If you want to build from source, this package contains compiled extendr Rust code to efficiently read GTFS-realtime. You will need a Rust development environment; you can build the Rust code by running rextendr::document().

Usage

GTFS-realtime feeds come in three flavors: vehicle positions, trip updates, and service alerts. This package exposes three functions, one for each type of file: read_gtfsrt_positions(), read_gtfsrt_trip_updates(), and read_gtfsrt_alerts(). We also have vignettes of working with each type of file: vehicle positions, trip updates, and service alerts.

For most analytical applications of GTFS-realtime, you will want to work with archived data. GTFS-realtime feeds can be quite large, so the package supports reading feeds compressed with ZIP, gzip, or bzip2 (anecdotally, bzip2 seems to provide slightly better compression than gzip). For zip files, it is also possible to have multiple GTFS-realtime feeds in a single file; in this case, the functions above will read all of the files in the ZIP file. You can differentiate records from different files with the file_index column. We also have an article demonstrating working with a day of archived data.

GTFS-realtime is a hierarchical format, and R data frames are flat tables. Thus, a single trip update or alert will become multiple rows in the output, with a common id. See the individual function documentation for details.