View source: R/integration-tidytransit.R
| download_feed | R Documentation |
A convenience function for downloading GTFS Schedule feeds from the Mobility Database. This is a "one-stop-shop" that can search for feeds by provider/location and download them in a single call, or download a specific feed by ID.
Note: This function is specifically designed for GTFS Schedule feeds only. GTFS Realtime and GBFS feeds use a different data model and are not supported by this function.
This function was formerly called mobdb_download_feed().
download_feed(
feed_id = NULL,
provider = NULL,
country_code = NULL,
subdivision_name = NULL,
municipality = NULL,
exclude_flex = TRUE,
feed_name = NULL,
use_source_url = FALSE,
dataset_id = NULL,
latest = TRUE,
status = "active",
official = NULL,
auth_args = NULL,
export_path = NULL,
raw = NULL,
...
)
feed_id |
A string or data frame. The unique identifier for the feed
(e.g., "mdb-2862"), or a single-row data frame from |
provider |
A string. Filter by provider/agency name (partial match). Use this to search for feeds without knowing the feed_id. |
country_code |
A string. Two-letter ISO country code (e.g., "US", "CA"). |
subdivision_name |
A string. State, province, or region name. |
municipality |
A string. City or municipality name. |
exclude_flex |
A logical. If |
feed_name |
A string. Optional filter for feed name. If provided, only
feeds whose |
use_source_url |
A logical. If |
dataset_id |
A string. Optional specific dataset ID for historical versions
(e.g., "mdb-53-202510250025"). If provided, downloads that specific dataset
version instead of the latest. Cannot be used with |
latest |
A logical. If |
status |
A string. Feed status filter: "active" (default), "deprecated", "inactive", "development", or "future". Only used when searching by provider/location. |
official |
A logical. If |
auth_args |
A string. Some agencies require authentication to download feeds directly from their source URLs. Provide your API key/token in one of two formats:
Also accepts a value stored in |
export_path |
A string. Optional path to save the GTFS feed as a ZIP file
(e.g., "data/gtfs/feed.zip"). By default, saves the raw file exactly as
downloaded. Set |
raw |
A logical. Controls whether the file saved to |
... |
Additional arguments passed to |
If export_path is provided with raw = TRUE (the default when
exporting), the file path (invisibly). If latest = TRUE, a gtfs object
as returned by tidytransit::read_gtfs().
If latest = FALSE, a tibble of all available datasets with their metadata.
mobdb_datasets() to list all available historical versions,
get_validation_report() to check feed quality before downloading,
feeds() to search for feeds,
mobdb_read_gtfs() for more flexible GTFS reading
# Download by feed ID
gtfs <- download_feed("mdb-2862")
# Download from search results
feeds <- feeds(provider = "TransLink", data_type = "gtfs")
gtfs <- download_feed(feeds[1, ])
# Search and download by provider name
gtfs <- download_feed(provider = "Arlington")
# Download using agency's source URL instead of Mobility Database
gtfs <- download_feed(provider = "TriMet", use_source_url = TRUE)
# See all available versions for a feed
versions <- download_feed("mdb-2862", latest = FALSE)
# Download a specific historical version (feed_id auto-extracted from dataset_id)
historical <- download_feed(dataset_id = "mdb-53-202507240047")
# Filter by location (may return multiple feeds requiring disambiguation,
# in which case refine with `provider` or `feed_name`)
try(download_feed(
country_code = "US",
subdivision_name = "California",
municipality = "San Francisco"
))
# Save GTFS feed to disk (raw file, no parsing required)
path <- download_feed("mdb-247", export_path = tempfile(fileext = ".zip"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.