# \dontshow{
old_dt_threads <- data.table::setDTthreads(1)
# }
library(dplyr)
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
# set a 30 seconds dwell time at a stop of a trip. the later times of the
# trip are shifted by 30 seconds
new_gtfs <- set_dwell_time(
gtfs,
trip_id = "CPTM L07-0",
stop_id = "18920",
dwell_time = 30
)
new_gtfs$stop_times |>
filter(trip_id == "CPTM L07-0") |>
head()
# set the dwell time at a stop in every trip that visits it. use the unit
# argument to give the dwell time in another unit
new_gtfs <- set_dwell_time(
gtfs,
stop_id = "18960",
dwell_time = 1,
unit = "min"
)
get_dwell_time(new_gtfs, stop_id = "18960")
# set the dwell time only at the visits that arrive within a time of day
new_gtfs <- set_dwell_time(
gtfs,
trip_id = "CPTM L07-0",
dwell_time = 30,
from = "05:00:00",
to = "06:00:00"
)
get_dwell_time(new_gtfs, trip_id = "CPTM L07-0")
# keep the trip duration: the running times between the stops absorb the
# dwell times, and the arrival at the last stop doesn't change
new_gtfs <- set_dwell_time(
gtfs,
trip_id = "CPTM L07-0",
dwell_time = 30,
strategy = "keep_total_duration"
)
new_gtfs$stop_times |>
filter(trip_id == "CPTM L07-0") |>
tail()
# original gtfs remains unchanged
get_dwell_time(gtfs, stop_id = "18960")
# when doing by reference, original gtfs is changed
set_dwell_time(
gtfs,
trip_id = "CPTM L07-0",
stop_id = "18920",
dwell_time = 30,
by_reference = TRUE
)
gtfs$stop_times |>
filter(trip_id == "CPTM L07-0") |>
head()
data.table::setDTthreads(old_dt_threads)
Run the code above in your browser using DataLab