Skip to content

R SDK

closecity is an R client over the Close API, built on httr2. It returns tabular results by default: an sf object where geometry applies (points, isochrone and block polygons) and a plain data.frame otherwise.

# install.packages("remotes")
remotes::install_github("henryspatialanalysis/closecity-r")
library(closecity)
# Your API key (ck_live_) is created at https://account.close.city.
close <- close_client("ck_live_your_key_here")
# Catalog routes are free and come back as data frames.
types <- close$destination_types()
# A radius search returns an sf of points, ready to map.
groceries <- close$pois_search(lat = 41.82, lon = -71.41, radius_m = 1500)
plot(sf::st_geometry(groceries))

Set output on the client, or per call:

  • output = "spatial" (the default) returns an sf object where geometry applies and a data.frame otherwise.
  • output = "tabular" returns a data.frame for every route and never downloads block boundaries. This is the cheap path when you only want numbers.
  • output = "raw" returns the underlying close_reply, with $tokens_charged, $etag, and the parsed body on $data.
close$output <- "raw"
summary <- close$block_summary("440070008001068", mode = "walk")
cat(summary$tokens_charged, "charged;", summary$tokens_remaining, "left\n")

Read every page of a paginated route with close$records("pois_search", ...). Metering and envelope metadata are attached as attributes on the returned frame.

The R SDK documentation has installation notes, a get-started vignette, worked tutorials, and the complete function reference. The API reference here documents every endpoint and response shape.