ITSLeeds / UK2GTFS

Convert UK transport data (TransXchange / ATOC CIF) to GTFS format in R
https://itsleeds.github.io/UK2GTFS/
GNU General Public License v3.0
37 stars 13 forks source link

Trouble reading TransXchange Open Bus Data Service #23

Closed noahbouchier closed 3 years ago

noahbouchier commented 3 years ago

Upon attempting to read in data from the DfT's Open Bus Data Service into R, using the UK2GTFS package, I'm receiving errors in the transxchange_import function.

The data comes from the Open Bus Data Service, found here: https://data.bus-data.dft.gov.uk/timetable/category/dataset/6/ - see attached zip file for cleaned data used in the code.

Minimal cleaning had to be undertaken on the "383_SMA_PC_383_20201025.xml" file, due to what looks like a typo, where an "Indicator" tag was mistyped as "Iroundicator".

Any help in successfully reading in these files would be greatly appreciated,

Thanks in advance

The full traceback

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ‘"xml_nodeset"’ to a data.frame

6. | stop(gettextf("cannot coerce class %s to a data.frame", sQuote(deparse(class(x))[1L])), domain = NA)
-- | --

5. | as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors)
-- | --

4. | as.data.frame(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors)
-- | --

3. | data.frame(NationalOperatorCode = NationalOperatorCode, OperatorCode = OperatorCode, OperatorShortName = OperatorShortName, OperatorNameOnLicence = OperatorNameOnLicence, TradingName = TradingName)
-- | --

2. | import_operators(operators = Operators)
-- | --

1. | transxchange_import(path_in[1])
-- | --

Code executed

library(UK2GTFS) # load package

base::getwd() # check working directory

path_in <- "/Users/noahbouchier/OneDrive - University of Bristol/Documents/_dissertation/diss_coding/stockport_xml/stagecoach-scmn-route-schedule-data-transxchange" # using working directory to navigate to the folder containing the xml files

path_in <- c(file.path(path_in, "383_SMA_PC_383_20200830.xml"), file.path(path_in, "383_SMA_PC_383_20201025.xml"))  # select desired xml file

path_out = "/Users/noahbouchier/OneDrive - University of Bristol/Documents/_dissertation/diss_coding/stockport_xml/GTFS" # select location to save xml files

scmn_gtfs <- transxchange_import(path_in[1]) # select gtfs files

383 xml data.zip

mem48 commented 3 years ago

This seems to be a tagging error the operators are called Operators rather than Operator and are slightly different structures.

I've made a small change which seems to work.

I haven't done a lot of testing with the new Open Bus Data Service so please report any other problems.

mem48 commented 3 years ago

Also OBDS now offers a national GTFS file which may be of use https://data.bus-data.dft.gov.uk/timetable/download/