Filters a GTFS object by stop_ids, keeping (or dropping) relevant entries
in each file.
Usage
filter_by_stop_id(
gtfs,
stop_id,
keep = TRUE,
include_children = TRUE,
include_parents = keep,
full_trips
)Arguments
- gtfs
A GTFS object, as created by
read_gtfs().- stop_id
A character vector. The
stop_ids used to filter the data.- keep
A logical. Whether the
stop_timesentries at the specifiedstop_ids (and the entries related to them in other tables) should be kept or dropped (defaults toTRUE, which keeps the entries). Trips that still have entries instop_timesare kept. To keep or drop entire trips, pass thetrip_ids that serve these stops tofilter_by_trip_id().- include_children
A logical. Whether the filtered output should keep/drop children stops of those specified in
stop_id. Defaults toTRUE- i.e. by default children stops are kept if their parents are kept and dropped if their parents are dropped.- include_parents
A logical. Whether the filtered output should keep/drop parent stations of those specified in
stop_id. Defaults to the same value ofkeep- i.e. by default parent stations are kept both when their children are kept and dropped, because they can be parents of multiple stops that are not necessarily dropped, even if their sibling are.- full_trips
Defunct. Deprecated in version 1.3.0 and removed in the following major version: using it, with any value, raises an error. The function now always filters by the specified stops. To keep all stops of the trips that pass through them, subset
stop_timesbystop_idand pass the resultingtrip_ids tofilter_by_trip_id().
Examples
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
stop_ids <- c("18848", "940004157")
object.size(gtfs)
#> 811304 bytes
# keeps the stop_times entries at the specified stop_ids
smaller_gtfs <- filter_by_stop_id(gtfs, stop_ids)
object.size(smaller_gtfs)
#> 64272 bytes
# drops the stop_times entries at the specified stop_ids
smaller_gtfs <- filter_by_stop_id(gtfs, stop_ids, keep = FALSE)
object.size(smaller_gtfs)
#> 809872 bytes
