soc_query | R Documentation |
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.
soc_query(
select = NULL,
where = NULL,
group_by = NULL,
having = NULL,
order_by = NULL,
limit = NULL
)
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. |
An object of class soc_query
, which prints in a readable format and can be used to build query URLs.
Use this with a function that executes Socrata requests, e.g., soc_read(url, query = soc_query(...))
query <- soc_query(
select = "region, avg(magnitude) as avg_magnitude, count(*) as count",
group_by = "region",
having = "count >= 5",
order_by = "avg_magnitude DESC"
)
print(query)
earthquakes_by_region <- soc_read(
"https://soda.demo.socrata.com/dataset/USGS-Earthquakes-2012-11-08/3wfw-mdbc/",
query = query
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.