UrbanAnalyst / gtfsrouter

Routing and analysis engine for GTFS (General Transit Feed Specification) data
https://urbananalyst.github.io/gtfsrouter/
81 stars 17 forks source link

column name 'trip_headsign' not found error #15

Closed polettif closed 5 years ago

polettif commented 5 years ago

Sorry for the possibly spammy issues but I had a look at this package again today and I've just run into these. If I try to run the router on this test feed I get the following error.

gtfs <- gtfsrouter::extract_gtfs("routing.zip")
gtfs <- gtfsrouter::gtfs_timetable(gtfs)
#> Day not specified; extracting timetable for Friday
gtfsrouter::gtfs_route(gtfs, from = "One", to = "Four", start_time = 7 * 3600)
#> Error in `[.data.table`(gtfs$trips, index, trip_headsign): j (the 2nd argument inside [...]) is a single symbol but column name 'trip_headsign' is not found. Perhaps you intended DT[, ..trip_headsign]. This difference to data.frame is deliberate and explained in FAQ 1.1.

Created on 2019-05-10 by the reprex package (v0.2.1)

It appears that gtfsrouter needs the optional trip_headsign column to work? Is there a way around that or should I simply add the column to the feed.

mpadge commented 5 years ago

@polettif don't apologise - this is really helping to make the package more robust, so much appreciated! That commit now yields this response:

gtfs <- gtfsrouter::extract_gtfs("/data/mega/code/repos/atfutures/gtfs-router/routing.zip")
gtfs <- gtfsrouter::gtfs_timetable(gtfs)
#> Day not specified; extracting timetable for Thursday
gtfsrouter::gtfs_route(gtfs, from = "One", to = "Four", start_time = 7 * 3600)
#>   route_name stop_name arrival_time departure_time
#> 1     Line D       One     07:17:00       07:17:00
#> 2     Line D     Three     07:23:00       07:23:00
#> 3     Line B     Three     07:28:00       07:29:00
#> 4     Line B      Four     07:37:00       07:37:00

Created on 2019-05-16 by the reprex package (v0.2.1)

The trip_name column simply does not appear when trips has no trip_headsign column. The fix is a bit hacky, and what I need to do is more systematically go through the entire GTFS specs and ensure every "Optional" table and field are appropriately handled when not present, and so -> #16