Skip to contents

Constructs a structured representation of a Socrata Query Language (SOQL) query that can be used with Socrata API endpoints. This function does not execute the query; it creates an object that can be passed to request functions or printed for inspection.

Usage

soc_query(
  select = NULL,
  where = NULL,
  group_by = NULL,
  having = NULL,
  order_by = NULL,
  limit = NULL
)

Arguments

select

string; Columns to retrieve.

where

string; Filter conditions.

group_by

string; Fields to group by.

having

string; Conditions to apply to grouped records.

order_by

string; Sort order.

limit

whole number; The maximum number of records to return.

Value

An object of class soc_query, which prints in a readable format and can be used to build query URLs.

See also

Use this with a function that executes Socrata requests, e.g., read_socrata(url, query = soc_query(...))

Examples

query <- soc_query(
  select = "pickup_community_area, count(*) as n",
  where = "dropoff_community_area = 31",
  group_by = "pickup_community_area",
  order_by = "n DESC"
)
print(query)
#> SELECT pickup_community_area, count(*) as n
#> WHERE dropoff_community_area = 31
#> GROUP BY pickup_community_area
#> ORDER BY n DESC

if (FALSE) { # \dontrun{
trips_to_lws_by_ca <- soc_read(
  "https://data.cityofchicago.org/Transportation/Taxi-Trips-2013-2023-/wrvz-psew/about_data",
  query = query
)
} # }