get_carto: Get data from the City's Carto API

Description Usage Arguments Examples

View source: R/carto.R

Description

Philadelphia's open data is published to carto, which allows you to query the data using SQL (specifically the PostgreSQL flavor with the PostGIS extension). Rather than executing the queries in a database program, they are executed through HTTP (ie. the web browser) via Carto's SQL API.

Usage

1
2
3
get_carto(query, format = "csv",
  base_url = "https://phl.carto.com/api/v2/sql", stringsAsFactors = F,
  ...)

Arguments

query

character, SQL query

format

character, desired response format, either "csv" (returned as data.frame) or "json" (parsed into list by jsonlite::fromJSON)

base_url

character, API endpoint, defaults to Philadelphia's Carto SQL endpoint

stringsAsFactors

logical, defaults to FALSE, applies to result if format = "csv"

...

other arguments passed either to read.csv or fromJSON, depending on format

Examples

1
2
3
4
5
6
7
query <- paste("SELECT service_name, COUNT(*) AS n",
               "FROM public_cases_fc",
               "GROUP BY service_name",
               "ORDER BY n DESC")

get_carto(query)
get_carto(query, format = "json")

CityOfPhiladelphia/rphl documentation built on Oct. 30, 2019, 5:44 a.m.