get_route: Get Route Information

View source: R/get_route.R

get_routeR Documentation

Get Route Information

Description

This function is a wrapper for the Route Service API. It returns the full route data in a tibble format, or a list of 2 tibbles with results and status information if desired.

Usage

get_route(
  token,
  start,
  end,
  route,
  date = Sys.Date(),
  time = format(Sys.time(), format = "%T"),
  mode = NULL,
  max_dist = NULL,
  n_itineraries = 3,
  status_info = FALSE,
  decode = FALSE
)

Arguments

token

User's API token. This can be retrieved using get_token

start

Vector of c(lat, lon) coordinates for the route start point

end

Vector of c(lat, lon) coordinates for the route end point

route

Type of route. Accepted values are walk, drive, pt (public transport), or cycle

date

Default = current date. Date for which route is requested.

time

Default = current time. Time for which route is requested.

mode

Required if route = "pt". Accepted values are transit, bus or rail

max_dist

Optional if route = "pt". Maximum walking distance

n_itineraries

Optional if route = "pt". Default = 3. The number of potential routes to provide.

status_info

Default = FALSE. Whether to return output as a list including a list of status information and a tibble of output

decode

Default = FALSE. If TRUE, output will be a sf dataframe displaying route geometry ('route_geom') instead of a tibble. Requires the 'sf' and 'googlePolylines' packages. Do note that the decoding of 'route_geom' is a lossy conversion.

Value

If no error occurs and status_info = TRUE:

status_info

A list containing information about the query status. If route = "pt", the output contains lists request_params, debug_output and elevation. Else, the list contains the variables status and status_msg

result

A tibble or sf dataframe containing the data retrieved from the query. This is the only output if status_info = FALSE. Each row is an itinerary. Output dimensions vary between route = "pt" and other routes

If an error occurs, the output will be NULL, along with a warning message.

Examples

# returns output tibble
## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive")
## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "pt",
    mode = "bus", max_dist = 300, n_itineraries = 2)
## End(Not run)

# returns output sf dataframe
## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581),
    "drive", decode = TRUE)
## End(Not run)
## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "pt",
    mode = "bus", max_dist = 300, n_itineraries = 2, decode = TRUE)
## End(Not run)

# returns list of status list and output tibble
## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581),
    "drive", status_info = TRUE)
## End(Not run)

# error: output is NULL, warning message shows status code
## Not run: get_route("invalid_token", c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive")

# error: output is NULL, warning message shows error message from request
## Not run: get_route(token, c(300, 300), c(400, 500), "cycle")
## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "fly")

onemapsgapi documentation built on Nov. 29, 2022, 9:06 a.m.