Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error with non-txt-files in zip #23

Closed
polettif opened this issue Jan 10, 2022 · 3 comments
Closed

error with non-txt-files in zip #23

polettif opened this issue Jan 10, 2022 · 3 comments

Comments

@polettif
Copy link
Collaborator

As mentioned in tidytransit issue #179 gtfsio has an issue with feeds containing file extensions other than txt. The issue is around import_gtfs#117 where "txt" is removed and later re-added, even if it hasn't been removed previously.

library(gtfsio)

ggl = import_gtfs(system.file("extdata", "ggl_gtfs.zip", package = "gtfsio"))
dir.create("gtfs_test")
data.table::fwrite(ggl$agency, "gtfs_test/agency.txt")
writeLines("dummy", "gtfs_test/nontxt.html")
zip::zip("gtfs_test.zip", list.files("gtfs_test", full.names = T), mode = "cherry-pick")

g = import_gtfs("gtfs_test.zip")
#> Error in zip::unzip(path, files = paste0(files_to_read, ".txt"), exdir = tmpdir, : zip error: `Cannot find file `nontxt.html.txt` in zip archive `/private/var/folders/p8/ck58x_354mj8vgdcqyyz_r540000gn/T/Rtmp0AZN1A/reprex-8294d23b73e-grave-cobra/gtfs_test.zip`` in file `zip.c:159`

I know files other than txt are not gtfs standard, I'd still suggest simply ignoring those files (something like the workaround in the linked issue) instead of throwing an error.

@dhersz
Copy link
Collaborator

dhersz commented Jan 10, 2022

Hi @polettif. Thanks for raising this issue.

e083a15 fixes this error. The function now ignores non text files when reading the GTFS feed, and raises an informative warning message explaining that these files were ignored.

library(gtfsio)

ggl = import_gtfs(system.file("extdata", "ggl_gtfs.zip", package = "gtfsio"))
dir.create("gtfs_test")
data.table::fwrite(ggl$agency, "gtfs_test/agency.txt")
writeLines("dummy", "gtfs_test/nontxt.html")
zip::zip("gtfs_test.zip", list.files("gtfs_test", full.names = T), mode = "cherry-pick")

g = import_gtfs("gtfs_test.zip")
#> Warning: Found non .txt files when attempting to read the GTFS feed: nontxt.html
#> These files have been ignored and were not imported to the GTFS object.

g
#> $agency
#>    agency_id    agency_name                         agency_url agency_timezone
#> 1: agency001 Transit Agency http://www.transitcommuterbus.com/             PST
#>    agency_lang
#> 1:          en

@dhersz dhersz closed this as completed Jan 10, 2022
@polettif
Copy link
Collaborator Author

Thanks for the quick resolution!

@dhersz
Copy link
Collaborator

dhersz commented Jan 10, 2022

No worries, it's my pleasure. I'll probably submit a new gtfsio version with this fix to CRAN by the end of the week, but the problem is currently solved by installing the dev version.

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

No branches or pull requests

2 participants