r5r is anR package for rapid realistic routing on multimodal transport networks (walk, bike, public transport and car). It provides a simple and friendly interface to R5, theRapid Realistic Routing on Real-world and Reimagined networks, the routing engine developed independently byConveyal.
r5r is a simple way to run R5 locally, allowingR users to generate detailed routing analysis or calculate travel time matrices and accessibility using seamless parallel computing. See a detailed demonstration ofr5r in theintro Vignette. More details aboutr5r can be found on thepackage webpage or on thispaper. Over time,r5r might be expanded to incorporate other functionality from R5.
This repository contains theR code (r-package folder) and the Java code (java-api folder) that provides the interface to R5.
Installation
You can installr5r:
# from CRANinstall.packages("r5r")# dev version with latest featuresutils::remove.packages('r5r')devtools::install_github("ipeaGIT/r5r", subdir="r-package")Please bear in mind that you need to haveJava Development Kit (JDK) 21 installed on your computer to user5r. No worries, you don’t have to pay for it. There are numerous open-source JDK implementations, any of which should work withr5r. If you don’t already have a preferred JDK, we recommendAdoptium/Eclipse Temurin. Other open-source JDK implementations includeAmazon Corretto, andOracle OpenJDK. You only need to install one JDK.
The easiest way to install JDK is using the new{rJavaEnv} package in R:
# install.packages('rJavaEnv')# check version of Java currently installed (if any)rJavaEnv::java_check_version_rjava()# install Java 21rJavaEnv::java_quick_install(version=21)Usage
The package has sevenfundamental functions :
build_network()- Downloads and stores locally an R5 Jar file (the Jar file is downloaded only once per installation)
- Builds a multimodal transport network given (1) a OpenStreetMap street network in
.pbfformat (mandatory), (2) one or more public transport networks inGTFS.zipformat (optional), and (3) elevation data inraster.tif(optional).
accessibility()- Fast computation of access to opportunities. The function returns a
data.tablewith accessibility estimates for all origin points by transport mode given a selected decay function. Multiple decay functions are available, including step (cumulative opportunities), logistic, fixed exponential and linear.
- Fast computation of access to opportunities. The function returns a
travel_time_matrix()- Fast function that returns a simple
data.tablewith travel time estimates between one or multiple origin destination pairs considering departure time.
- Fast function that returns a simple
arrival_travel_time_matrix()- Calculates travel time matrices between origin destination pairs considering a time of arrival. The output includes additional information such as the routes used and total time disaggregated by access, waiting, in-vehicle and transfer times.
expanded_travel_time_matrix()- Calculates travel time matrices between origin destination pairs with additional information such as routes used and total time disaggregated by access, waiting, in-vehicle and transfer times.
detailed_itineraries()- Returns a
data.frame sf LINESTRINGswith one or multiple alternative routes between one or multiple origin destination pairs. The data output brings detailed information on transport mode, travel time, walk distance etc for each trip segment.
- Returns a
pareto_frontier()- Returns a
data.tablewith the travel time and monetary cost of multiple route alternatives for specified origin-destination pairs.
- Returns a
isochrone()- Returns a
sf" "data.frame"showing the area that can be reached from an origin point at a given travel time limit.
- Returns a
See more details about each function here
obs. Most of these functions also allow users to account for monetary travel costs when generating travel time matrices and accessibility estimates. More info on how to consider monetary costs can be found inthis vignette.
The package also includes a fewsupport functions.
street_network_to_sf()- Extract OpenStreetMap network in sf format from a
network.datfile.
- Extract OpenStreetMap network in sf format from a
transit_network_to_sf()- Extract transit network in sf format from a
network.datfile.
- Extract transit network in sf format from a
find_snap()- Find snapped locations of input points on street network.
r5r_sitrep()- Generate a situation report to help debug eventual errors.
Data requirements:
To user5r, you will need: - A road network data set from OpenStreetMap in.pbf format (mandatory) - A public transport feed inGTFS.zip format (optional) - A raster file of Digital Elevation Model data in.tif format (optional)
Here are a few places from where you can download these data sets:
- OpenStreetMap
- osmextract R package
- geofabrik website
- hot export tool website
- BBBike.org website
- Protomaps website
- GTFS
- tidytransit R package
- transitland website
- Mobility Database website
- Elevation
- elevatr R package
- Nasa’s SRTMGL1 website
Demonstration on sample data
See a detailed demonstration ofr5r in thisintro Vignette. To illustrate functionality, the package includes a small sample data set of the public transport and Open Street Map networks of Porto Alegre (Brazil). Three steps are required to user5r, as follows.
# allocate RAM memory to Java **before** loading the {r5r} libraryoptions(java.parameters="-Xmx2G")library(r5r)# 1) build transport network, pointing to the path where OSM and GTFS data are storedpath<-system.file("extdata/poa", package="r5r")r5r_network<-build_network(data_path=path, verbose=FALSE)# 2) load origin/destination points and set argumentspoints<-read.csv(system.file("extdata/poa/poa_hexgrid.csv", package="r5r"))mode<-c("WALK","TRANSIT")max_walk_time<-30# minutesmax_trip_duration<-60# minutesdeparture_datetime<-as.POSIXct("13-05-2019 14:00:00", format="%d-%m-%Y %H:%M:%S")# 3.1) calculate a travel time matrixttm<-travel_time_matrix(r5r_network=r5r_network, origins=points, destinations=points, mode=mode, departure_datetime=departure_datetime, max_walk_time=max_walk_time, max_trip_duration=max_trip_duration)# 3.2) or get detailed info on multiple alternative routesdet<-detailed_itineraries(r5r_network=r5r_network, origins=points[370,], destinations=points[200,], mode=mode, departure_datetime=departure_datetime, max_walk_time=max_walk_time, max_trip_duration=max_trip_duration, shortest_path=FALSE, drop_geometry=FALSE)# 4) Calculate number of schools accessible within 20 minutesaccess<-accessibility(r5r_network=r5r_network, origins=points, destinations=points, opportunities_colname="schools", decay_function="step", cutoffs=21, mode=c("WALK","TRANSIT"), verbose=FALSE)Related packages
There is a growing number ofR packages with functionalities for transport routing, analysis and planning more broadly. Here are few of theses packages.
- dodgr: Distances on Directed Graphs in R
- gtfsrouter: R package for routing with GTFS data
- hereR: an R interface to the HERE REST APIs
- opentripplanner: OpenTripPlanner for R
- stplanr: sustainable transport planning with R
Ther5r package is particularly focused on fast multimodal transport routing and accessibility. A key advantage ofr5r is that is provides a simple and friendly R interface to R5, one of the fastest and most robust routing engines available.
ForPython users, you might want to check our sister package:r5py!
Acknowledgement
TheR5 routing engine is developed atConveyal with contributions from several people.
Citation
The R packager5r is developed by a team at the Institute for Applied Economic Research (Ipea), Brazil. If you use this package in research publications, we please cite it as:
- Pereira, R. H. M., Saraiva, M., Herszenhut, D., Braga, C. K. V., & Conway, M. W. (2021).r5r: Rapid Realistic Routing on Multimodal Transport Networks with R5 in R.Findings, 21262.https://doi.org/10.32866/001c.21262
BibTeX:
@article{pereira_r5r_2021, title = {r5r: Rapid Realistic Routing on Multimodal Transport Networks with {R}$^{\textrm{5}}$ in R}, shorttitle = {r5r}, url = {https://findingspress.org/article/21262-r5r-rapid-realistic-routing-on-multimodal-transport-networks-with-r-5-in-r}, doi = {10.32866/001c.21262}, language = {en}, urldate = {2021-03-04}, journal = {Findings}, author = {Pereira, Rafael H. M. and Saraiva, Marcus and Herszenhut, Daniel and Braga, Carlos Kaue Vieira and Conway, Matthew Wigginton}, month = mar, year = {2021}, note = {Publisher: Network Design Lab}}Please also cite the relevant publications relating to the R⁵ engine on whichr5r builds up:
- Conway, M. W., Byrd, A., & van der Linden, M. (2017):Evidence-Based Transit and Land Use Sketch Planning Using Interactive Accessibility Methods on Combined Schedule and Headway-Based Networks.Transportation Research Record, 2653(1), 45–53.DOI:10.3141/2653-06
- Conway, M. W., Byrd, A., & Van Eggermond, M. (2018):Accounting for uncertainty and variation in accessibility metrics for public transport sketch planning.Journal of Transport and Land Use, 11(1).DOI:10.5198/jtlu.2018.1074
- Conway, M. W. & Stewart, A. F. (2019):Getting Charlie off the MTA: a multiobjective optimization method to account for cost constraints in public transit accessibility metrics.International Journal of Geographical Information Science, 33(9), 1759–1787.DOI:10.1080/13658816.2019.1605075

