50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

GTFSwizard (version 1.1.0)

delay_trip: Delay Specified Trips in a `wizardgtfs` Object

Description

This function adds a delay to the arrival and departure times of specified trips within a `wizardgtfs` object. If the input GTFS object is not of class `wizardgtfs`, it will be converted.

Usage

delay_trip(gtfs, trip, duration)

Value

A modified `wizardgtfs` object with updated arrival and departure times for the specified trips.

Arguments

gtfs

An object representing GTFS data, preferably of class `wizardgtfs`.

trip

A character vector of `trip_id`s in the `wizardgtfs` object that will be delayed. Each `trip_id` must exist in `gtfs$trips$trip_id`.

duration

A delay duration, either as a `duration` object or a numeric value representing seconds.

Details

This function adjusts the arrival and departure times of the specified `trip_id`s in `gtfs$stop_times` by the specified `duration`. If `gtfs` is not a `wizardgtfs` object, the function will attempt to convert it using `GTFSwizard::as_wizardgtfs()`, and a warning will be issued. The function checks that `trip` contains valid `trip_id`s and that `duration` is either a `duration` or numeric (seconds).

See Also

[GTFSwizard::as_wizardgtfs()] for converting GTFS objects to `wizardgtfs` class.

Examples

Run this code
# Delay trips by 5 minutes
gtfs <- delay_trip(gtfs = for_rail_gtfs, for_rail_gtfs$trips$trip_id[1:2], duration = 300)

# Delay trips by duration
gtfs <- delay_trip(gtfs = for_rail_gtfs,
                    trip = for_rail_gtfs$trips$trip_id[1],
                    duration = lubridate::duration(10, "minutes"))

Run the code above in your browser using DataLab