Skip to content

Fixed missing prefix on stops.txt$parent_station on merge_gtfs() method#93

Merged
rafapereirabr merged 1 commit into
ipea:mainfrom
gmatosferreira:patch-2
May 22, 2026
Merged

Fixed missing prefix on stops.txt$parent_station on merge_gtfs() method#93
rafapereirabr merged 1 commit into
ipea:mainfrom
gmatosferreira:patch-2

Conversation

@gmatosferreira
Copy link
Copy Markdown
Contributor

According to GTFS official documentation, stops.txt has a column parent_station that references a stops.txt$stop_id. However, the method gtfstools::merge_gtfs() only considers the columns that end with _id when applying the prefix parameter, which is generating an invalid parent_station column in the merged GTFS when this column exists.

id_cols <- names(dt)[(grepl("_id$", names(dt)))]

image

GTFS documentation for stops.txt parent_station column

image

Example of output for TCB GTFS (https://backend.tcbarreiro.pt/download-gtfs) with a prefix equal to the agency_id, where we can see that only the stop_id was changed, while the parent_station remain unchanged.

With a simple refactoring to include parent_station in the id_cols filter fixes this.

@gmatosferreira
Copy link
Copy Markdown
Contributor Author

I just validated the changes locally using remotes::install_github("gmatosferreira/gtfstools", ref="patch-2") and this change fixes the problem I report.

image

@rafapereirabr
Copy link
Copy Markdown
Collaborator

thanks, @gmatosferreira . nice catch and simple fix !

@rafapereirabr rafapereirabr merged commit 2589ae4 into ipea:main May 22, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants