Skip to contents

Provides an R interface to the cycle planning API, a route planner made by cyclists for cyclists. The function returns a SpatialLinesDataFrame object representing the an estimate of the fastest, quietest or most balance route. Currently only works for the United Kingdom and part of continental Europe, though other areas may be requested by contacting CycleStreets. See more information.


  plan = "fastest",
  silent = TRUE,
  pat = NULL,
  base_url = "",
  reporterrors = TRUE,
  save_raw = "FALSE"



Text string or coordinates (a numeric vector of length = 2 representing latitude and longitude) representing a point on Earth.


Text string or coordinates (a numeric vector of length = 2 representing latitude and longitude) representing a point on Earth. This represents the destination of the trip.


Text strong of either "fastest" (default), "quietest" or "balanced"


Logical (default is FALSE). TRUE hides request sent.


The API key used. By default this is set to NULL and this is usually aquired automatically through a helper, api_pat().


The base url from which to construct API requests (with default set to main server)


Boolean value (TRUE/FALSE) indicating if cyclestreets (TRUE by default). should report errors (FALSE by default).


Boolean value which returns raw list from the json if TRUE (FALSE by default).


This function uses the online routing service to find routes suitable for cyclists between origins and destinations. Requires an internet connection, a API key and origins and destinations within the UK (and various areas beyond) to run.

Note that if from and to are supplied as character strings (instead of lon/lat pairs), Google's geo-coding services are used via geo_code().

You need to have an api key for this code to run. Loading a locally saved copy of the api key text string before running the function, for example, will ensure it is available on any computer:

mytoken <- readLines("~/Dropbox/dotfiles/cyclestreets-api-key-rl") Sys.setenv(CYCLESTREETS = mytoken)

if you want the API key to be available in future sessions, set it using the .Renviron file with usethis::edit_r_environ()

Read more about the .Renviron here: ?.Renviron

See also



if (FALSE) {
from <- c(-1.55, 53.80) # geo_code("leeds")
to <- c(-1.76, 53.80) # geo_code("bradford uk")
json_output <- route_cyclestreets(from = from, to = to, plan = "quietest", save_raw = TRUE)
str(json_output) # what does cyclestreets give you?
rf_lb <- route_cyclestreets(from, to, plan = "fastest")
(rf_lb$length / (1000 * 1.61)) / # distance in miles
  (rf_lb$time / (60 * 60)) # time in hours - average speed here: ~8mph