Read and Write General Transit Feed Specification (GTFS) Files

Tools for the development of packages related to General Transit Feed Specification (GTFS) files. Establishes a standard for representing GTFS feeds using R data types. Provides fast and flexible functions to read and write GTFS feeds while sticking to this standard. Defines a basic 'gtfs' class which is meant to be extended by packages that depend on it. And offers utility functions that support checking the structure of GTFS objects.


gtfsio gtfsio logo

CRANstatus gtfsio statusbadge Bstatus Codecov testcoverage Lifecycle:maturing CRAN/METACRAN Totaldownloads

gtfsio offers tools for the development of GTFS-related packages. It establishes a standard for representing GTFS feeds using R data types based on the GTFS Schedule Reference. It provides fast and flexible functions to read and write GTFS feeds while sticking to this standard. It defines a basic gtfs class which is meant to be extended by packages that depend on it. And it also offers utility functions that support checking the structure of GTFS objects.

Installation

Stable version:

install.packages("gtfsio")

Development version:

install.packages("gtfsio", repos = "https://r-transit.r-universe.dev")

# or
# install.packages("remotes")
remotes::install_github("r-transit/gtfsio")

Usage

GTFS feeds are read using the import_gtfs() function:

library(gtfsio)

path <- system.file("extdata/ggl_gtfs.zip", package = "gtfsio")

gtfs <- import_gtfs(path)

names(gtfs)
#>  [1] "calendar_dates"  "fare_attributes" "fare_rules"      "feed_info"      
#>  [5] "frequencies"     "levels"          "pathways"        "routes"         
#>  [9] "shapes"          "stop_times"      "stops"           "transfers"      
#> [13] "translations"    "trips"           "agency"          "attributions"   
#> [17] "calendar"

import_gtfs() returns a gtfs object which is a list of a tables. The gtfs class might be extended by other packages using the constructor, validator and methods provided by gtfsio:

class(gtfs)
#> [1] "gtfs" "list"

Use export_gtfs() to write GTFS objects to disk:

tmpf <- tempfile(fileext = ".zip")

export_gtfs(gtfs, tmpf)

zip::zip_list(tmpf)$filename
#>  [1] "calendar_dates.txt"  "fare_attributes.txt" "fare_rules.txt"     
#>  [4] "feed_info.txt"       "frequencies.txt"     "levels.txt"         
#>  [7] "pathways.txt"        "routes.txt"          "shapes.txt"         
#> [10] "stop_times.txt"      "stops.txt"           "transfers.txt"      
#> [13] "translations.txt"    "trips.txt"           "agency.txt"         
#> [16] "attributions.txt"    "calendar.txt"

For a more complete demonstration please read the introductory vignette.

GTFS-related packages

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("gtfsio")

1.2.2 by Flavio Poletti, 2 days ago


https://r-transit.github.io/gtfsio/, https://github.com/r-transit/gtfsio


Report a bug at https://github.com/r-transit/gtfsio/issues


Browse source code at https://github.com/cran/gtfsio


Authors: Daniel Herszenhut [aut] (ORCID: , Flavio Poletti [aut, cre] , Mark Padgham [aut] , Rafael H. M. Pereira [rev] (ORCID: , Tom Buckley [rev] , Ipea - Institute for Applied Economic Research [cph, fnd]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports data.table, fs, utils, zip, jsonlite

Suggests knitr, rmarkdown, tinytest


Imported by GTFSwizard, gtfstools, tidytransit.

Suggested by mobdb.


See at CRAN