Crunch Expressions, i.e.
encapsulate derivations of Crunch variables, possibly composed of other functions
which are only evaluated when sent to the server when creating a variable using
as.vector() to get data. The crunch database functions can be found in the
and can be called directly via
crunchdbFunc()m but many have also been wrapped
in native R functions, and are described in the details section below.
crunchdbFunc(fun, x, ...)
The name of the crunch database function to call
An input, a crunch variable, expression or R object
Other arguments passed to the database function
These logical operators
%in% work the same way as their
base R counterparts
CrunchLogicalExpr whether a value is in a selected category
rowAll(x) work row-wise on
MultipleResponse Variables (and expressions),
na.rm is not implemented for
%ornm% is similar to
|, but where "not selected" beats "missing" (so
FALSE %ornm% NA
FALSE instead of
NA as it would be with
FALSE | NA)
>= work the same way as their base R counterparts.
crunchBetween(x, lower, upper, inclusive) to provide lower and upper bounds in a single
Missing data expressions
CrunchLogicalExpr whether a single variable (or expression
that creates one) is missing (or not missing).
CrunchLogicalExpr whether any/all values in an
array variable (or expression that creates one) are missing.
complete.cases(x) returns an expression that is "selected" if all cases are non-missing,
"missing" if they are all missing, and "other" otherwise.
selectCategories(x, selections, collapse = TRUE) takes a categorical variable (or array)
and marks categories as selected.
selections should be a list of category names or
TRUE, (the default), it collapses the categories to "selected",
"other" and "missing", but it is
FALSE, then the old categories are preserved.
asSelected(x) returns an expression that condenses a categorical into 3 categories
("selected", "other" or "missing")
selectedDepth(x) returns an expression that creates a numeric variable that counts the
number of selections across rows of an array variable (or expression that creates one)
arraySelections(x) returns an expression that takes an array and creates an array with
each variable condensed to "selected", "other" or "missing" and an extra subvariable
"any" that indicates whether any is selected.
alterCategoriesExpr(x, categories = NULL, category_order = NULL, subvariables = NULL)
Change the category names, order, or subvariable names of categorical or Array variables
(can only modify existing ones, not add or remove categories or subvariables).
categories is a
Categories object or a list of lists, each with a
the new name, as well as an
old_name to identify which category to modify.
category_order is either a numeric vector indicating category ids or a character vector
indicating the names of the categories in the order they should be displayed
(note that all categories must be specified).
subvariables is a list of lists, each with
name to rename the subvariable and an
id to identify the
x is an expression, all categories and subvariables must be identified
makeFrame(x, numeric = NULL) an expression that creates an array from existing
variables or expressions, see
deriveArray() for more details
arraySubsetExpr(x, subvars, subvar_id = c("alias", "name", "id")) Take a subset of an
existing array variable, identifying the subvariables by alias, name, or id (if
an expression, you must use id).
alterArrayExpr( x, add = NULL, order = NULL, order_id = c("alias", "name", "id"), remove = NULL, remove_id = c("alias", "name", "id"), subreferences = NULL, subreferences_id = c("alias", "name", "id") )
Add, reorder, remove or rename subvariables on an an array variable
add argument is
a list of variables or expressions, optionally named with the id they should have.
remove are vectors of aliases, names or ids (specify which with
subreferences object is a list of lists that are named the alias, name, or id (again
specify which with
subreferences_id) with metadata information like name and alias in the
caseExpr(..., cases) Create a categorical variable from
a set of logical expressions that when met are assigned to a category. See
makeCaseVariable() for more details.
bin(x) returns a column's values binned into equidistant bins.
nchar(x) returns a numeric value indicating the length of a string (or missing reason)
TextVariable (or expression that creates one)
unmissing(x) for a
NumericVariable (or expression that creates one) return the values of
the data, ignoring the ones set to missing.
trim(x, min, max) for a
NumericVariable (or expression that creates one) return values
that where all values less than
min have been replaced with
min and all values greater
max have been
crunchDifftime(e1, e2, resolution) Gets the difference between two datetimes as a number
with specified resolution units (one of
c("Y", "Q", "M", "W", "D", "h", "m", "s", "ms")).
datetimeFromCols(year, month, day, hours, minutes, seconds) create a
from numeric variables or expressions (
day are required, but
seconds are optional)
rollup(x, resolution) sets the resolution of a datetime variable or expression, see