Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
polettif committed Oct 14, 2024
1 parent 43f055a commit d7c7d16
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 104 deletions.
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
#' Data obtained from
#' \url{https://data.trilliumtransit.com/gtfs/duke-nc-us/duke-nc-us.zip}.
#' @docType data
#' @seealso read_gtfs
#' @seealso [read_gtfs()]
"gtfs_duke"
3 changes: 0 additions & 3 deletions R/dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

#' Returns all possible date/service_id combinations as a data frame
#'
#' Use it to summarise service. For example, get a count of the number of
#' services for a date. See example.
#'
#' @param gtfs_obj gtfs feed (tidygtfs object)
#' @return a date_service data frame
#'
Expand Down
6 changes: 3 additions & 3 deletions R/geo.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#' @return Returns a data.frame with each row containing a pair of stop_ids (columns
#' `from_stop_id` and `to_stop_id`) and the `distance` between them (in meters)
#'
#' @note The resulting data.frame has nrow(gtfs_stops)^2 rows, distances calculations
#' among all stops for large feeds should be avoided
#' @note The resulting data.frame has `nrow(gtfs_stops)^2` rows, distances calculations
#' among all stops for large feeds should be avoided.
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -93,7 +93,7 @@ prep_dist_mtrx = function(dist_list) {
#' By default calculates distances among stop_ids with the same stop_name.
#'
#' @inheritParams stop_distances
#' @param by group column, default: stop_name
#' @param by group column, default: "stop_name"
#'
#' @returns data.frame with one row per group containing a distance matrix (distances),
#' number of stop ids within that group (n_stop_ids) and distance summary values
Expand Down
40 changes: 22 additions & 18 deletions R/io.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#' Read and validate GTFS files
#'
#' Reads GTFS text files from either a local \code{.zip} file or an URL and
#' validates them against GTFS specifications.
#' Reads a GTFS feed from either a local `.zip` file or an URL and validates them againts
#' GTFS specifications.
#'
#' @param path The path to a GTFS \code{.zip} file.
#' @param files A character vector containing the text files to be read from the
#' GTFS (without the \code{.txt} extension). If \code{NULL} (the default) all
#' existing files are read.
#' @param files A character vector containing the text files to be validated against the GTFS
#' specification without the file extension (`txt` or `geojson`). If `NULL` (the default),
#' all existing files are read.
#' @param quiet Whether to hide log messages and progress bars (defaults to TRUE).
#' @param ... Can be used to pass on arguments to [gtfsio::import_gtfs()]. The parameters
#' \code{files} and \code{quiet} are passed on by default.
#' `files` and `quiet` are passed on by default.
#'
#' @return A tidygtfs object: a list of tibbles in which each entry represents a
#' GTFS text file. Additional tables are stored in the \code{.} sublist.
#' @return A tidygtfs object: a list of tibbles in which each entry represents a GTFS text
#' file. Additional tables are stored in the \code{.} sublist.
#'
#' @seealso \code{\link{validate_gtfs}}
#' @seealso [validate_gtfs()], [write_gtfs()]
#'
#' @examples \dontrun{
#' local_gtfs_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
Expand All @@ -35,16 +35,20 @@ read_gtfs <- function(path, files = NULL, quiet = TRUE, ...) {
}

#' Write a tidygtfs object to a zip file
#'
#' @note Auxilliary tidytransit tables (e.g. \code{dates_services}) are not exported.
#'
#'
#' @note Auxilliary tidytransit tables (e.g. \code{dates_services}) are not exported. Calls
#' [gtfsio::export_gtfs()] after preparing the data.
#'
#' @param gtfs_obj gtfs feed (tidygtfs object)
#' @param zipfile path to the zip file the feed should be written to
#' @param compression_level a number between 1 and 9.9, passed to zip::zip
#' @param as_dir if TRUE, the feed is not zipped and zipfile is used as a directory path.
#' Files within the directory will be overwritten.
#' @return Invisibly returns gtfs_obj
#'
#' @param zipfile path to the zip file the feed should be written to. The file is overwritten
#' if it already exists.
#' @param compression_level a number between 1 and 9, defaults to 9 (best compression).
#' @param as_dir if `TRUE`, the feed is not zipped and zipfile is used as a directory path.
#' The directory will be overwritten if it already exists.
#' @return Invisibly returns `gtfs_obj`
#'
#' @seealso [read_gtfs()]
#'
#' @importFrom gtfsio export_gtfs
#' @export
write_gtfs <- function(gtfs_obj, zipfile, compression_level = 9, as_dir = FALSE) {
Expand Down
5 changes: 2 additions & 3 deletions R/plot.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Plot GTFS stops and trips
#'
#' @param x a gtfs_obj as read by read_gtfs()
#' @param ... further specifications
#' @param x a tidygtfs object as read by [read_gtfs()]
#' @param ... ignored for tidygtfs
#' @return plot
#'
#' @examples \donttest{
Expand All @@ -13,7 +13,6 @@
#' }
#'
#' @importFrom graphics plot
#' @importFrom dplyr select
#' @export
plot.tidygtfs <- function(x, ...) {
dots <- list(...)
Expand Down
6 changes: 0 additions & 6 deletions R/raptor.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
#' travel time is returned. With `earliest` the journey arriving at a stop the
#' earliest is returned, `latest` works accordingly.
#'
#' All departures from `stop_ids` within
#' the time range stop_id in
#' `stop_ids`) within `time_range` are considered. If `arrival` is TRUE,
#' all arrivals within `time_range` before the latest arrival time of
#' stop_times are considered.
#'
#' @return A data.table with journeys (departure, arrival and travel time) to/from all
#' stop_ids reachable by `stop_ids`.
#'
Expand Down
5 changes: 4 additions & 1 deletion R/spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,15 @@ gtfs_transform = function(gtfs_obj, crs) {

#' Convert stops and shapes from sf objects to tibbles
#'
#' Coordinates are transformed to lon/lat
#' Coordinates are transformed to lon/lat columns (`stop_lon`/`stop_lat` or
#' `shape_pt_lon`/`shape_pt_lat`)
#'
#' @param gtfs_obj gtfs feed (tidygtfs object)
#'
#' @return tidygtfs object with stops and shapes converted to tibbles
#'
#' @seealso \code{\link{gtfs_as_sf}}
#'
#' @export
sf_as_tbl = function(gtfs_obj) {
if(inherits(gtfs_obj$stops, "sf")) {
Expand Down
9 changes: 5 additions & 4 deletions R/summary.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#' Print a GTFS object
#'
#' Prints a GTFS object suppressing the \code{class} attribute.
#' Prints a GTFS object suppressing the \code{class} attribute and hiding the
#' validation_result attribute, created with [validate_gtfs()].
#'
#' @param x A GTFS object.
#' @param x a tidygtfs object as read by [read_gtfs()]
#' @param ... Optional arguments ultimately passed to \code{format}.
#'
#' @return The GTFS object that was printed, invisibly
Expand All @@ -25,12 +26,12 @@ print.tidygtfs = function(x, ...) {

#' GTFS feed summary
#'
#' @param object a gtfs_obj as read by [read_gtfs()]
#' @param object a tidygtfs object as read by [read_gtfs()]
#' @export
#'
#' @return the tidygtfs object, invisibly
#'
#' @param ... further specifications
#' @param ... ignored for tidygtfs
#' @importFrom dplyr select arrange filter
summary.tidygtfs <- function(object, ...) {
dots <- list(...)
Expand Down
2 changes: 1 addition & 1 deletion R/tidygtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ as_tidygtfs.gtfs = function(x, ...) {

#' @export
as_tidygtfs.dt_gtfs = function(x, ...) {
gtfs_to_tidygtfs(x)
gtfs_to_tidygtfs(x, ...)
}

#' @export
Expand Down
16 changes: 9 additions & 7 deletions R/time.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' convert a vector of time strings
#' Convert "HH:MM:SS" time strings to hms values
#' empty strings are converted to NA
#' @param time_strings char vector ("HH:MM:SS")
#' @keywords internal
Expand All @@ -17,8 +17,9 @@ hhmmss_to_hms <- function(time_strings) {
return(hms::new_hms(time_seconds))
}

#' Function to convert "HH:MM:SS" time strings to seconds.
#' @param hhmmss_str string
#' Convert "HH:MM:SS" time strings to seconds (numeric)
#' empty strings are converted to NA
#' @param hhmmss_str char vector ("HH:MM:SS")
#' @keywords internal
hhmmss_to_seconds <- function(hhmmss_str) {
as.numeric(substr(hhmmss_str, 0, 2)) * 3600 +
Expand Down Expand Up @@ -55,11 +56,12 @@ replace_NA_times = function(stop_times) {
# interpolate stop_times ####

#' Interpolate missing stop_times linearly
#' Uses shape_dist_traveled if available
#'
#' @param x tidygtfs object or stop_times table
#' @param use_shape_dist if available, use shape_dist_traveled column for time
#' interpolation. If shape_dist_traveled is missing, times
#' are interpolated equally between stops.
#' @param use_shape_dist If TRUE, use `shape_dist_traveled` column from the shapes table for
#' time interpolation (if that column is available). If FALSE or
#' `shape_dist_traveled` is missing, times are interpolated equally
#' between stops.
#' @return tidygtfs or stop_times with interpolated arrival and departure times
#' @examples
#' \dontrun{
Expand Down
12 changes: 6 additions & 6 deletions R/validate_gtfs.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#' Validate GTFS file
#' Validate GTFS feed
#'
#' Validates the GTFS object against GTFS specifications and raises warnings if
#' required files/fields are not found. This function is called in \code{\link{read_gtfs}}.
#' required files/fields are not found. This function is called in [read_gtfs()].
#'
#' Note that this function just checks if required files or fields are missing. There's no
#' validation for internal consistency (e.g. no departure times before arrival times or
#' calendar covering a reasonable period).
#'
#' @param gtfs_obj gtfs object (i.e. a list of tables, not necessary a tidygtfs object)
#' @param files A character vector containing the text files to be validated
#' against the GTFS specification (without the \code{.txt} extension). If
#' \code{NULL} (the default) the provided GTFS is validated against all
#' against the GTFS specification without the file extension (`txt` or `geojson`). If
#' `NULL` (the default), the provided GTFS feed is validated against all
#' possible GTFS text files.
#' @param warnings Whether to display warning messages (defaults to TRUE).
#' @param warnings Whether to display warning messages (defaults to `TRUE`).
#'
#' @return A \code{validation_result} tibble containing the validation summary of all
#' possible fields from the specified files.
Expand Down Expand Up @@ -40,7 +40,7 @@
#' \item \code{feed_info.txt} is initially set as an optional file. If
#' \code{translations.txt} is present, however, it becomes required.
#' }
#'
#'
#' @examples
#' validate_gtfs(gtfs_duke)
#' #> # A tibble: 233 × 8
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ reference:
- filter_feed_by_stops
- filter_feed_by_trips
- filter_stops
- title: "Analyse"
- title: "Analyse GTFS objects"
contents:
- validate_gtfs
- set_servicepattern
Expand Down
2 changes: 1 addition & 1 deletion man/gtfs_duke.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/hhmmss_to_hms.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/hhmmss_to_seconds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions man/interpolate_stop_times.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/plot.tidygtfs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/print.tidygtfs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions man/raptor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d7c7d16

Please sign in to comment.