Raises the dwell time of each specified trip_id at each specified
stop_id to at least min_dwell_time, i.e. makes vehicles stay at least
that long at the stops, by delaying the departure_time at these stops in
stop_times and shifting the later times of the trips accordingly.
Usage
set_min_dwell_time(
gtfs,
min_dwell_time,
unit = "s",
trip_id = NULL,
stop_id = NULL,
from = NULL,
to = NULL,
route_type = NULL,
by_reference = FALSE
)Arguments
- gtfs
A GTFS object, as created by
read_gtfs().- min_dwell_time
A non-negative number, the minimum dwell time, in
unit. It's rounded to the nearest whole second.- unit
A string representing the time unit in which
min_dwell_timeis given. One of"s"(seconds, the default),"min"(minutes),"h"(hours) or"d"(days).- trip_id
A character vector including the
trip_ids to have their dwell times raised. IfNULL(the default), the dwell times of everytrip_idin the GTFS (or of every trip of the givenroute_types) are raised.- stop_id
A character vector including the
stop_ids at which the dwell times are raised. IfNULL(the default), the dwell times are raised at everystop_idin the GTFS.- from
A string, in the "HH:MM:SS" format. Only visits whose arrival time is at or after
fromare changed. IfNULL(the default), there is no lower limit.- to
A string, in the "HH:MM:SS" format. Only visits whose arrival time is at or before
toare changed. IfNULL(the default), there is no upper limit.- route_type
An integer vector of
route_types (seefilter_by_route_type()). If given, only trips of routes of these types are changed; together with the other selection arguments, it restricts their selection.route_types not listed inroutesare ignored. IfNULL(the default), trips of any type are changed.- by_reference
Whether to update
stop_times'data.tableby reference. Defaults toFALSE.
Value
If by_reference is set to FALSE, returns a GTFS object with the
time columns of its stop_times adjusted. Else, returns a GTFS object
invisibly (note that in this case the original GTFS object is altered).
Details
Visits are selected as in set_dwell_time(). At each selected visit whose
dwell time is shorter than min_dwell_time, the arrival time is kept and
the departure time is set to the arrival time plus min_dwell_time.
The first and last visits with both an arrival and a departure time of each
trip are never raised (use set_dwell_time() for them). They are found
among all the visits of the trip, not only the selected ones, and the times
of the last visit may still be shifted by an earlier visit.
Negative dwell times (departure earlier than arrival) are raised like any
other shorter dwell time, so a min_dwell_time of 0 raises only these.
Times after midnight written as early morning times are fixed first, as in
set_dwell_time(), so they don't result in negative dwell times.
Otherwise it works as set_dwell_time().
Examples
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
# vehicles stay 0 seconds at the stops of this trip. make them stay at least
# 30 seconds at each intermediate stop
head(get_dwell_time(gtfs, trip_id = "CPTM L07-0"))
#> trip_id stop_id stop_sequence dwell_time
#> <char> <char> <int> <num>
#> 1: CPTM L07-0 18940 1 0
#> 2: CPTM L07-0 18920 2 0
#> 3: CPTM L07-0 18919 3 0
#> 4: CPTM L07-0 18917 4 0
#> 5: CPTM L07-0 18916 5 0
#> 6: CPTM L07-0 18965 6 0
new_gtfs <- set_min_dwell_time(gtfs, 30, trip_id = "CPTM L07-0")
head(get_dwell_time(new_gtfs, trip_id = "CPTM L07-0"))
#> trip_id stop_id stop_sequence dwell_time
#> <char> <char> <int> <num>
#> 1: CPTM L07-0 18940 1 0
#> 2: CPTM L07-0 18920 2 30
#> 3: CPTM L07-0 18919 3 30
#> 4: CPTM L07-0 18917 4 30
#> 5: CPTM L07-0 18916 5 30
#> 6: CPTM L07-0 18965 6 30
