cached_route_types: Retrieve route types, using cached values if possible

View source: R/route-types.R

cached_route_typesR Documentation

Retrieve route types, using cached values if possible

Description

Route types will change extraordinarily rarely — this would require PTV to add a new route type akin to "train" or "bus". To avoid querying the API too much, we prefer to use cached values for route type translation wherever possible. This function effectively wraps route_types, returning cached results if possible or caching results otherwise. Note that if a user specifically calls route_types then we do not return cached results.

We use the pkg_env as a cache, which is an environment created on package load. This is not truly private — users could still access this as an internal value. But it's effectively "out of the way".

Usage

cached_route_types(
  user_id = determine_user_id(),
  api_key = determine_api_key()
)

Arguments

user_id

Integer or character. A user ID or devid provided by Public Transport Victoria. Refer to ?ptvapi for more details.

api_key

Character. An API key, with dashes, provided by Public Transport Victoria. Refer to ?ptvapi for more details.

Value

A named integer vector in which the values are the route type descriptions, and the names of the vector are the route type numbers.


ptvapi documentation built on May 29, 2024, 4:48 a.m.