View source: R/utils-gtfs-format.R
| gtfs_to_spec_format | R Documentation |
Converts a tidygtfs object (as returned by tidytransit::read_gtfs())
back to GTFS-spec-compliant string formats. This reverses tidytransit's
automatic type conversions:
Date columns (R Date objects) are converted back to YYYYMMDD strings
(e.g., as.Date("2024-01-15") becomes "20240115")
Time columns (hms/difftime objects) are converted back to HH:MM:SS
strings, preserving values >= 24:00:00 for trips past midnight
(e.g., hms::hms(hours = 25, minutes = 30) becomes "25:30:00")
Columns that are already in the correct format (character or integer) are left unchanged. Returns a modified copy; the original object is not modified.
gtfs_to_spec_format(gtfs)
gtfs |
A gtfs/tidygtfs object, typically from |
A modified copy of the gtfs object with date and time columns converted to GTFS-spec-compliant strings.
Date columns (YYYYMMDD):
calendar: start_date, end_date
calendar_dates: date
feed_info: feed_start_date, feed_end_date
Time columns (HH:MM:SS):
stop_times: arrival_time, departure_time
frequencies: start_time, end_time
gtfs <- download_feed("mdb-247")
# Dates are R Date objects from tidytransit
class(gtfs$calendar$start_date)
# [1] "Date"
# Convert to GTFS-spec format
spec <- gtfs_to_spec_format(gtfs)
spec$calendar$start_date
# [1] "20240101"
spec$stop_times$arrival_time[1]
# [1] "08:30:00"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.