TargomoR package is designed to be an R interface to the Targomo travel time service, through their REST API. The goal is to make it easy for R users to access the data, so they can spend more time doing analysis and less time wrestling with API documentation.
The functions in
TargomoR are designed to integrate with those of
leaflet - functions for adding features and tiles to a
leaflet map for example all take the form
addTargomo*, and can be piped together using
Underlying the functions to talk to the API is the
httr::POST function. Each request is composed by translating your data and options into a suitable JSON request,
POSTing it to the API, and processing the JSON response into an
Targomo provides a range of travel-time services as end-points from their API. Currently supported services are detailed in the table below. Please see the linked articles for more information on each service.
|Options (all services)||
As well as the
addTargomo* functions there are also separate corresponding
drawTargomo* functions which return the data from the API as a usable R object and draw it on the map (respectively). These provide flexibility, and are particularly useful if you’re conducting further analysis with the data, rather than immediately visualising it.
The following code snippet shows how easy it is to add detailed routing data to a
leaflet map, in just a few function calls. Try clicking the red public transport lines for more information about the route!
# load packages library(leaflet) library(TargomoR) # set source and target data source <- data.frame(id = "Big Ben", lat = 51.5007, lng = -0.1246) target <- data.frame(id = "Tower Bridge", lat = 51.5055, lng = -0.0754) # create map and add a basemap and routes leaflet() %>% addTargomoTiles(style = "basic") %>% addTargomoRoutes(source_data = source, target_data = target, options = targomoOptions( travelType = "transit", transitMaxTransfers = 1 )) %>% addTargomoAttribution(position = "bottomleft") #> Assuming "lng" and "lat" are longitude and latitude, respectively #> Assuming "lng" and "lat" are longitude and latitude, respectively
Check out the detailed articles for more information.