get_gbfs: Grab bikeshare data

View source: R/get_gbfs.R

get_gbfsR Documentation

Grab bikeshare data

Description

get_gbfs grabs bikeshare data supplied in the General Bikeshare Feed Specification format for a given city. By default, the function returns the results as a named list of dataframes, but to make accumulation of datasets over time straightforward, the user can also save the results as .Rds files that will be automatically row-binded. Metadata for each dataset can be found at: https://github.com/NABSA/gbfs/blob/master/gbfs.md

Usage

get_gbfs(city, feeds = "all", directory = NULL, output = NULL)

Arguments

city

A character string that can be matched to a city or a url to an active gbfs.json feed. See get_gbfs_cities for a current list of available cities.

feeds

Optional. A character string specifying which feeds should be saved. Options are "all", "static", and "dynamic".

directory

Optional. Path to a folder (or folder to be created) where the feed will will be saved.

output

Optional. The type of output method. By default, output method will be inferred from the directory argument. If output = "save", the dataframes will be saved as .rds objects in the given folder. If output = "return", the results will be returned as a named list of dataframes. Setting output = "both" will do both. If both are left as NULL, the result will be returned and not saved to file.

Value

The output of this function depends on the arguments supplied to output and directory. Either a folder of .rds dataframes saved at the given path, a returned named list of dataframes, or both. The function will raise an error if the directory and output arguments seem to conflict.

Examples

# grab all of the feeds released by portland's 
# bikeshare program and return them as a 
# named list of dataframes
get_gbfs(city = "biketown_pdx")

# if, rather than returning the data, we wanted to save it:
get_gbfs(city = "biketown_pdx", directory = tempdir())

# note that, usually, we'd supply a character string 
# (like "pdx", maybe,) to the directory argument 
# instead of `tempdir()`. 

# if we're having trouble specifying the correct feed,
# we can also supply the actual URL to the feed
get_gbfs(city = "https://gbfs.biketownpdx.com/gbfs/gbfs.json")
                   
# the examples above grab every feed that portland releases.
# if, instead, we just wanted the dynamic feeds
get_gbfs(city = "biketown_pdx", feeds = "dynamic")

gbfs documentation built on Aug. 15, 2022, 5:09 p.m.

Related to get_gbfs in gbfs...