Skip to content

Issue with routing on merged GTFS feeds #150

@zz-carol

Description

@zz-carol

Hi, thank you for developing and maintaining gtfsrouter. It has been very helpful for my project.

I am working on a use case where I combine multiple GTFS feeds (from different transit agencies in the same region) and then perform routing across the merged network. I ran into an issue where routing either fails or crashes, depending on the setup.

When combining multiple GTFS feeds using gtfstools::merge_gtfs() and then routing with gtfs_route(), in some cases, it returns NULL even when a valid route exists. In other cases (specifically on Linux / Posit Workbench), the R session crashes with exit code 134 (SIGABRT) when max_transfers = 0.

This is an example that works with a single GTFS feed:

library(gtfsrouter)
library(gtfstools)
library(tidytransit)

route_stops_tri = read_gtfs("https://gotriangle.tripsparkhost.com/gtfs/Realtime/google_transit.zip")
gtfstools::write_gtfs(route_stops_tri, "go_triangle_gtfs.zip")

gtfs_final = extract_gtfs("go_triangle_gtfs.zip")
gtfs_final = gtfs_transfer_table(gtfs_final, d_limit = 300)

itinerary = gtfs_route(
  gtfs_final,
  from = c(-78.9439, 36.0090),
  to = c(-78.9585, 35.9659),
  start_time = "11:00:00",
  max_transfers = 0
)

This correctly returns a direct route.

This is an example that fails with merged GTFS feeds:

urls = c(
  godurham = "https://godurham.rideralerts.com/InfoPoint/GTFS-Zip.ashx",
  gotriangle = "https://gotriangle.tripsparkhost.com/gtfs/Realtime/google_transit.zip"
)

gtfs_list = lapply(urls, read_gtfs)
gtfs_combined = do.call(merge_gtfs, gtfs_list)

gtfstools::write_gtfs(gtfs_combined, "merged_gtfs.zip")

gtfs_final = extract_gtfs("merged_gtfs.zip")
gtfs_final = gtfs_transfer_table(gtfs_final, d_limit = 300)

itinerary = gtfs_route(
  gtfs_final,
  from = c(-78.9439, 36.0090),
  to = c(-78.9585, 35.9659),
  start_time = "11:00:00",
  max_transfers = 0
)

This either returns NULL or crashes the R session with exit code 134 (on Linux) when I merge more GTFS, even when a direct route exists.

After merging feeds, I also noticed nrow(gtfs_final$timetable) returns NULL, which may indicate the timetable is not being constructed correctly. The crash appears to originate from C++ code (csa.cpp) with an out-of-bounds access: std::vector<bool>::operator[] ... assertion "__n < this->size()".

My question is whether combining multiple GTFS feeds is expected to work with gtfsrouter, or is this currently unsupported? Any insights on this issue will be appreciated! Thank you again for your work on this package!

This is my session info:

R version 4.5.3 (2026-03-11)
Platform: x86_64-redhat-linux-gnu
Running under: Fedora Linux 43 (Server Edition)

Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-THREADS;  LAPACK version 3.12.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/New_York
tzcode source: system (glibc)

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bslib_0.10.0      shiny_1.13.0      osrm_5.0.0        gtfsrouter_0.1.4  gtfstools_1.4.0  
 [6] tidytransit_1.8.0 sf_1.1-0          leaflet_2.2.3     TSP_1.2.7         dodgr_0.4.3      
[11] osmdata_0.3.0     maps_3.4.3        lubridate_1.9.5   forcats_1.0.1     stringr_1.6.0    
[16] dplyr_1.2.1       purrr_1.2.2       readr_2.2.0       tidyr_1.3.2       tibble_3.3.1     
[21] ggplot2_4.0.2     tidyverse_2.0.0  

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1        farver_2.1.2            S7_0.2.1               
 [4] fastmap_1.2.0           promises_1.5.0          googlePolylines_0.8.7  
 [7] digest_0.6.39           timechange_0.4.0        mime_0.13              
[10] lifecycle_1.0.5         processx_3.8.7          magrittr_2.0.5         
[13] compiler_4.5.3          mapiso_0.3.0            rlang_1.2.0            
[16] sass_0.4.10             tools_4.5.3             utf8_1.2.6             
[19] data.table_1.18.2.1     htmlwidgets_1.6.4       classInt_0.4-11        
[22] curl_7.0.0              xml2_1.5.2              RColorBrewer_1.1-3     
[25] gtfsio_1.2.0            rsconnect_1.8.0         KernSmooth_2.23-26     
[28] withr_3.0.2             RcppSimdJson_0.1.15     grid_4.5.3             
[31] xtable_1.8-8            e1071_1.7-17            scales_1.4.0           
[34] iterators_1.0.14        isoband_0.3.0           dichromat_2.0-0.1      
[37] cli_3.6.6               generics_0.1.4          otel_0.2.0             
[40] RcppParallel_5.1.11-2   rstudioapi_0.18.0       tzdb_0.5.0             
[43] DBI_1.3.0               cachem_1.1.0            proxy_0.4-29           
[46] s2_1.1.9                vctrs_0.7.3             jsonlite_2.0.0         
[49] callr_3.7.6             hms_1.1.4               crosstalk_1.2.2        
[52] foreach_1.5.2           jquerylib_0.1.4         units_1.0-1            
[55] glue_1.8.0              codetools_0.2-20        ps_1.9.2               
[58] leaflet.providers_3.0.0 stringi_1.8.7           gtable_0.3.6           
[61] later_1.4.8             pillar_1.11.1           rappdirs_0.3.4         
[64] htmltools_0.5.9         R6_2.6.1                httr2_1.2.2            
[67] wk_0.9.5                memoise_2.0.1           renv_1.1.8             
[70] httpuv_1.6.17           class_7.3-23            Rcpp_1.1.1             
[73] geodist_0.1.1           xfun_0.57               fs_2.0.1               
[76] flexiblas_3.4.0         pkgconfig_2.0.3   

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions