Coerce lists and GTFS objects from other packages into gtfstools-compatible GTFS objects
Source:R/dt_gtfs.R
as_dt_gtfs.Rd
Coerces an existing object, such as a list
or a GTFS object created from
other packages ({tidytransit}
and {gtfsio}
, for example) into a
gtfstools-compatible GTFS object - i.e. one whose internal tables are
represented with data.table
s and whose fields are formatted like the fields
of a feed read with read_gtfs()
.
as_dt_gtfs()
is an S3 generic, with methods for:
tidygtfs
: the class of GTFS objects read withtidytransit::read_gtfs()
. This method converts alltibble
s todata.table
s and convert time columns, represented ashms
objects in atidygtfs
, to strings in the"HH:MM:SS"
format.gtfs
: the class of GTFS objects read withgtfsio::import_gtfs()
. This method convert all date fields, represented asinteger
s in{gtfsio}
's representation, toDate
objects.list
: this method tries to convert the elements of a list intodata.table
s. Please note that all list elements must inherit fromdata.frame
and must be named. This method does not try not convert fields to the representation used in{gtfstools}
, as it does not have any information on how they are formatted in the first place.
Usage
as_dt_gtfs(gtfs, ...)
# S3 method for class 'tidygtfs'
as_dt_gtfs(gtfs, calculate_distance = TRUE, ...)
# S3 method for class 'gtfs'
as_dt_gtfs(gtfs, ...)
# S3 method for class 'list'
as_dt_gtfs(gtfs, ...)
Arguments
- gtfs
The object that should be coerced to a
dt_gtfs
.- ...
Ignored.
- calculate_distance
A logical. Passed to
convert_sf_to_shapes()
, which only affects the output when the object to be converted includes ashapes
element. Controls whether this function, used to convert aLINESTRING sf
into a GTFSshapes
table, should calculate and populate theshape_dist_traveled
column. This column is used to describe the distance along the shape from each one of its points to its first point. Defaults toTRUE
.
Examples
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfsio_gtfs <- gtfsio::import_gtfs(data_path)
class(gtfsio_gtfs)
#> [1] "gtfs" "list"
gtfstools_gtfs <- as_dt_gtfs(gtfsio_gtfs)
class(gtfstools_gtfs)
#> [1] "dt_gtfs" "gtfs" "list"
gtfs_like_list <- unclass(gtfsio_gtfs)
class(gtfs_like_list)
#> [1] "list"
gtfstools_gtfs <- as_dt_gtfs(gtfs_like_list)
class(gtfstools_gtfs)
#> [1] "dt_gtfs" "gtfs" "list"