Learn R Programming

gtfsio

gtfsio offers tools for the development of GTFS-related packages. It establishes a standard for representing GTFS feeds using R data types based on Google’s Static GTFS 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://dhersz.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"     
#>  [4] "feed_info"       "frequencies"     "levels"         
#>  [7] "pathways"        "routes"          "shapes"         
#> [10] "stop_times"      "stops"           "transfers"      
#> [13] "translations"    "trips"           "agency"         
#> [16] "attributions"    "calendar"

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

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

Use the export_gtfs() function 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"
#>  [3] "fare_rules.txt"      "feed_info.txt"      
#>  [5] "frequencies.txt"     "levels.txt"         
#>  [7] "pathways.txt"        "routes.txt"         
#>  [9] "shapes.txt"          "stop_times.txt"     
#> [11] "stops.txt"           "transfers.txt"      
#> [13] "translations.txt"    "trips.txt"          
#> [15] "agency.txt"          "attributions.txt"   
#> [17] "calendar.txt"

For a more complete demonstration please read the introductory vignette.

GTFS-related packages

Copy Link

Version

Install

install.packages('gtfsio')

Monthly Downloads

998

Version

1.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Daniel Herszenhut

Last Published

October 11th, 2024

Functions in gtfsio (1.2.0)

assert_gtfs

GTFS object validator
gtfsio-package

gtfsio: Read and Write General Transit Feed Specification (GTFS) Data
check_file_exists

Check the existence of text files in a GTFS object
check_field_class

Check the classes of fields in a GTFS object element
get_gtfs_standards

Generate GTFS standards
export_gtfs

Export GTFS objects
check_field_exists

Check the existence of fields in a GTFS object element
print.gtfs

Print a GTFS object
import_gtfs

Import GTFS transit feeds
summary.gtfs

Print summary of a GTFS object
[.gtfs

Subset a GTFS object
translate_types

Translate GTFS specification types to R equivalent types
read_geojson

Read geojson file
read_files

Read a GTFS text file
gtfs_reference

GTFS reference
gtfsio_error

gtfsio's custom error condition constructor
parent_function_error

Parent error function constructor
assert_vector

Assert that an input is a vector/list with desired properties
new_gtfs

GTFS object constructor