Skip to content

R and httr: Pulling data from a Web API to obtain realtime bus transit information from Champaign–Urbana Mass Transit District (CUMTD).

Notifications You must be signed in to change notification settings

coatless-r-n-d/r-web-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retrieving Data from a Custom Web API

R-CMD-check

The cumtd R package provides an example of implementing and using a Web API. In particular, the package is a case study in retrieving data from the Champaign-Urbana Mass Transit District (‘CUMTD’) Web API, which provides realtime information for buses. Writing a custom wrapper to the API was necessary since there is not a realtime General Transit Feed Specification (GTFS) available via GTFS Realtime. Thus, for those wanting to know if their bus will arrive on time, one must look elsewhere.

As a follow-up, the package is used in r-shinydashboard example to illustrate how a real-time API can be used with shinydashboard.

Installation

To install the cumtd package, use:

if(!requireNamespace("remotes")) install.packages("remotes")
remotes::install_github("coatless-r-n-d/r-web-api")

To access its contents, load it into R with:

library("cumtd")

Endpoints

We have support presently for:

Implemented Functions
classify_departure_status
convert_response
cumtd
cumtd_check_key
cumtd_set_key
cumtd_show_key
get_all_routes
get_all_stops
get_all_vehicles
get_api_usage
get_departures_by_stop
get_route_shape
get_route_shape_between_stops

End points to be added (PRs appreciated!):

End Point Documentation
GetCalendarDatesByDate
GetCalendarDatesByService
GetNews
GetReroutes
GetReroutesByRoute
GetRoute
GetRoutesByStop
GetStop
GetStopsByLatLon
GetStopsBySearch
GetStopTimesByTrip
GetStopTimesByStop
GetPlannedTripsByLatLon
GetPlannedTripsByStops
GetTrip
GetTripsByBlock
GetTripsByRoute
GetVehicle
GetVehiclesByRoute
GetLastFeedUpdate

Implementation Details

When trying to import data into R from a Web API, the preferred approach is to use httr or curl. Using either of these packages, one can form HTTP requests to send to the Web API and receive HTTP responses from it that contain the data. Inside the response, there is a body portion that contains the desired data and needs to be converted into an R data structure.

License

GPL (>= 2)

About

R and httr: Pulling data from a Web API to obtain realtime bus transit information from Champaign–Urbana Mass Transit District (CUMTD).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages