Learn R Programming

Causata (version 4.2-0)

Query: Build queries to extract data from Causata.

Description

The Query class is used to generate SQL queries for Causata. The queries are built with the helper objects WithVariables, Where and Limit. SQL is generated when as.character() is invoked on the query object.

Usage

Query()
"Limit"(this, ...)
"Limit"(this) <- value
"Variables"(this, ...)
"Variables"(this) <- value
WithVariables(...)

Arguments

this
A query object.
value
For Query this is a number indicating the maximum number of records to return. For Variables this is one or more variable names in a list.
...
For WithVariables this is a single variable, or a list of variables. For Query and Variables this is unused extra arguments.

Value

returns a blank Query object.

Details

The Query object builds a query for customer data, a blank Query corresponds to

SELECT * FROM Customers variable

This query can be made more specific by adding variables with WithVariables, adding where clauses with Where or setting a row limit with Limit. The actual SQL query can be generated with as.character, e.g. as.character(Query()).

The variables and limit can be retrieved and modified with Variables(query) and Limit(query) respectively.

See Also

FocalPointQuery, Connect, Variables, Where, CausataData, is.

Examples

Run this code
q <- Query()
q <- q + WithVariables(c("var1", "var2"))
q <- q + Where("variable-one", GreaterThan(30))
Variables(q) # returns c("var1", "var2")
Variables(q) <- c("var2", "var3") # set the variables for this query
Limit(q) # since the limit has not been set this returns NULL
Limit(q) <- 1000 # Sets the limit to 1000
as.character(q)

q <- Query() + WithVariables("variable-one", "variable-two") + 
  Where("variable-one", GreaterThan(5))
# The example below is commented out since it requires a server connection.
# With a connection this would retrieve data and return it in a dataframe df.
## Not run: 
# conn <- Connect(hostname, port, username, password)
# data <- GetData(conn, q)
# ## End(Not run)

Run the code above in your browser using DataLab