@@ -122,7 +122,7 @@ m4ra_gtfs_traveltimes <- function (gtfs,
122122 res_i [res_i == .Machine $ integer.max ] <- NA_integer_
123123
124124 rownames (res_i ) <- stops
125- colnames (res_i ) <- gtfs $ stops $ stop_id
125+ colnames (res_i ) <- gtfs $ stop_ids $ stop_id
126126
127127 # diag (res_i) <- 0L # diagonals set in "prepare-data" routines
128128
@@ -140,6 +140,13 @@ m4ra_gtfs_traveltimes <- function (gtfs,
140140
141141# ' Main function to calculate intervals to next fastest connection, called from
142142# ' `m4ra_gtfs_traveltimes()` if `next_interval = TRUE`.
143+ # '
144+ # ' @param res Result of rcpp_traveltimes as a list of matrices (n, 3), where n
145+ # ' is the number of "stop_id" values in gtfs$stops. The 'gtfs_next_start_times'
146+ # ' routine returns a matrix with number of rows equal to 'nrow(gtfs$stop_ids)',
147+ # ' which is generally less, because that is unique IDs only. The two have to
148+ # ' reconciled below.
149+ # '
143150# ' @noRd
144151gtfs_next_intervals <- function (gtfs , stops , res , start_time_limits ) {
145152
@@ -173,6 +180,10 @@ gtfs_next_intervals <- function (gtfs, stops, res, start_time_limits) {
173180 )
174181 next_starts [next_starts < = 0 ] <- NA_integer_
175182
183+ # reduce dimension to only unique stops:
184+ index <- match (gtfs $ stop_ids $ stop_ids , gtfs $ stops $ stop_id )
185+ next_starts <- next_starts [, index ]
186+
176187 first_starts <- lapply (res , function (i ) as.vector (i [, 1 ]))
177188 first_starts <- do.call (rbind , first_starts )
178189 first_starts [first_starts == .Machine $ integer.max | first_starts < = 0 ] <- NA_integer_
@@ -182,7 +193,7 @@ gtfs_next_intervals <- function (gtfs, stops, res, start_time_limits) {
182193 # diag (next_interval) <- NA_integer_
183194
184195 rownames (next_interval ) <- stops
185- colnames (next_interval ) <- gtfs $ stops $ stop_id
196+ colnames (next_interval ) <- gtfs $ stop_ids $ stop_id
186197
187198 return (next_interval )
188199}
0 commit comments