Returns the (recursive) parent stations of each specified stop_id. Recursive in this context means it returns all parents' parents (i.e. first parents, then parents' parents, and then their parents, and so on).

get_parent_station(gtfs, stop_id = NULL)



A GTFS object, as created by read_gtfs().


A string vector including the stop_ids to have their parents returned. If NULL (the default), the function returns the parents of every stop_id in the GTFS.


A data.table containing the stop_ids and their parent_stations. If a stop doesn't have a parent, its correspondent parent_station entry is marked as "".


data_path <- system.file("extdata/", package = "gtfstools")

gtfs <- read_gtfs(data_path)

parents <- get_parent_station(gtfs)
#>    stop_id parent_station
#> 1:     F12               
#> 2:      E1            F12
#> 3:      E2            F12
#> 4:      E3            F12
#> 5:      E4            F12
#> 6:      E5            F12

# use the stop_id argument to control which stops are analyzed
parents <- get_parent_station(gtfs, c("B1", "B2"))
#>    stop_id parent_station
#> 1:      B1           F12S
#> 2:      B2           F12N
#> 3:    F12S            F12
#> 4:    F12N            F12
#> 5:     F12