Title: | Helps Make Socrata Open Data API Calls |
---|---|
Description: | Used to construct the URLs and parameters of 'Socrata Open Data API' <https://dev.socrata.com> calls, using the API's 'SoQL' parameter format. Has method-chained and sensical syntax. Plays well with pipes. |
Authors: | Zeb Burke-Conte |
Maintainer: | "Zeb Burke-Conte" <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-11-01 11:15:38 UTC |
Source: | https://github.com/zmbc/soql |
Used to construct the URLs and parameters of 'Socrata Open Data API' <https://dev.socrata.com> calls, using the API's 'SoQL' parameter format. Has method-chained and sensical syntax. Plays well with pipes.
To create a SoQL URL, or just parameters for one, start with soql()
. Then chain the result into other functions, such as soql_where()
or soql_order()
. When you're done, use as.character()
to retrieve the finished URL, for use with any networking package.
Zeb Burke-Conte
Maintainer: "Zeb Burke-Conte" <[email protected]>
Documentation for the SODA API
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_where("height > 30") %>% soql_limit(20) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_where(soql_chain, "height > 30") soql_chain <- soql_limit(20) my_url <- as.character(soql_chain) }
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_where("height > 30") %>% soql_limit(20) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_where(soql_chain, "height > 30") soql_chain <- soql_limit(20) my_url <- as.character(soql_chain) }
soql
object
This is the constructor for soql
objects. It will most often be called with no parameters, and be used at the start of a chain of functions. It is necessary to use this function before any others in the soql package.
soql(query = "")
soql(query = "")
query |
An optional string containing an already-formed URL. This URL is converted into a |
Returns a soql
object.
soql() soql("a.socrata.endpoint?$select=*&$order=height")
soql() soql("a.socrata.endpoint?$select=*&$order=height")
Add an endpoint to an already-existing soql
object.
soql_add_endpoint(soql_list, endpoint)
soql_add_endpoint(soql_list, endpoint)
soql_list |
The |
endpoint |
The endpoint should be the URL of the data, without any parameters. |
Returns a new soql
object, with the endpoint added, for use in other functions.
Socrata's documentation on what an endpoint is
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_add_endpoint("https://fake.soda.api/resource.json") %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_add_endpoint(soql_chain, "https://fake.soda.api/resource.json") my_url <- as.character(soql_chain) }
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_add_endpoint("https://fake.soda.api/resource.json") %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_add_endpoint(soql_chain, "https://fake.soda.api/resource.json") my_url <- as.character(soql_chain) }
Adds a parameter to the SODA URL that limits how many responses the API will send back.
soql_limit(soql_list, limit)
soql_limit(soql_list, limit)
soql_list |
The |
limit |
Number of records desired. |
Returns a new soql
object, with a limit parameter added, for use in other functions.
Documentation on the SODA website
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_limit(5) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_limit(soql_chain, 5) my_url <- as.character(soql_chain) }
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_limit(5) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_limit(soql_chain, 5) my_url <- as.character(soql_chain) }
This function adds a parameter to a soql
object that controls what index the returned records start at. For more information, view the SODA documentation linked in the References section below.
soql_offset(soql_list, offset)
soql_offset(soql_list, offset)
soql_list |
The |
offset |
Desired starting index of responses. |
Returns a new soql
object, with an offset parameter added, for use in other functions.
Documentation on the SODA website
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_offset(50) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_offset(soql_chain, 50) my_url <- as.character(soql_chain) }
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_offset(50) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_offset(soql_chain, 50) my_url <- as.character(soql_chain) }
Wrapper functions around the SODA API's queries: select
, where
, order
, group
, and q
.
soql_select(soql_list, select_clause) soql_where(soql_list, where_clause) soql_order(soql_list, column, desc = FALSE) soql_group(soql_list, group_clause) soql_q(soql_list, q_clause)
soql_select(soql_list, select_clause) soql_where(soql_list, where_clause) soql_order(soql_list, column, desc = FALSE) soql_group(soql_list, group_clause) soql_q(soql_list, q_clause)
soql_list |
The |
select_clause , where_clause , group_clause , q_clause
|
String to be used as the given clause in the query. |
column |
Column name to be ordered by. |
desc |
Whether to order descending. |
Returns a new soql
object, with parameters added, for use in other functions.
Documentation about these queries on the SODA website
soql_simple_filter
for an easier method of doing where
with equality.
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_select("height,weight") %>% soql_where("height > 30") %>% soql_order("height", desc=TRUE) %>% soql_group("type") %>% soql_q("a") %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_select(soql_chain, "height,weight") soql_chain <- soql_where(soql_chain, "height > 30") soql_chain <- soql_order(soql_chain, "height", desc=TRUE) soql_chain <- soql_group(soql_chain, "type") soql_chain <- soql_q(soql_chain, "a") my_url <- as.character(soql_chain) }
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_select("height,weight") %>% soql_where("height > 30") %>% soql_order("height", desc=TRUE) %>% soql_group("type") %>% soql_q("a") %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_select(soql_chain, "height,weight") soql_chain <- soql_where(soql_chain, "height > 30") soql_chain <- soql_order(soql_chain, "height", desc=TRUE) soql_chain <- soql_group(soql_chain, "type") soql_chain <- soql_q(soql_chain, "a") my_url <- as.character(soql_chain) }
This function adds a parameter to the URL to filter records in a simple way, using equality only. For more advanced filters, see soql_where
.
soql_simple_filter(soql_list, column, value)
soql_simple_filter(soql_list, column, value)
soql_list |
The |
column |
The column name to filter by. |
value |
The value the column must be equal to. |
Returns a new soql
object, with a filter parameter added, for use in other functions.
Documentation on the SODA website
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_simple_filter("height", 50) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_simple_filter(soql_chain, "height", 50) my_url <- as.character(soql_chain) }
if (require(magrittr)) { # With pipes my_url <- soql() %>% soql_simple_filter("height", 50) %>% as.character() } else { # Without pipes soql_chain <- soql() soql_chain <- soql_simple_filter(soql_chain, "height", 50) my_url <- as.character(soql_chain) }