Skip to contents

Operator are functions of maximum two arguments. The first argument is interpreted as a field (e.g. column name), the second one as a filtering value interpreted by operator accordingly. Some operators, such as 'is_empty' (that compares field values to empty string) don't require any value provided.

Usage

queryOperator(method)

setQueryOperators(..., .queryBuilderConfig = queryBuilderConfig)

listQueryOperators(.queryBuilderConfig = queryBuilderConfig, print = TRUE)

default_operators

Format

An object of class list of length 20.

Arguments

method

R function the operator should be transformed to when parsing result to R expression. The function should take at most two parameters. The first one (obligatory) is variable vector, the second one additional parameters interpreted by operator. Could be negated with exclamation mark e.g. queryOperator(!startsWith) which will be interpreted as the negation of the associated expression.

...

Name-value pairs defining operator name and method respectively. Should be defined with usage of queryOperator function.

.queryBuilderConfig

R6 class object storing query configuration. See queryBuilderConfigClass.

print

Should the list of operators be printed into console?

Value

A single `quote` storing the provided method.

Details

Operators are stored as quotes, that are further interpreted while converting the query to filtering expression.

  • queryOperator: defines a custom operator that can be used in generated query.

  • setQueryOperators: is used to register the defined operators in the default or custom queryBuilderConfigClass object.

  • listQueryOperators: allows to list available operators for the specific column type.

  • default_operators: an object storing default definitions for operators.

Examples


listQueryOperators()
#> equal: ==
#> not_equal: !=
#> in: %in%
#> not_in: !`%in%`
#> less: <
#> less_or_equal: <=
#> greater: >
#> greater_or_equal: >=
#> between: queryBuilder::in_range
#> not_between: !queryBuilder::in_range
#> begins_with: startsWith
#> not_begins_with: !startsWith
#> contains: queryBuilder::in_string
#> not_contains: !queryBuilder::in_string
#> ends_with: endsWith
#> not_ends_with: !endsWith
#> is_empty: queryBuilder::is_empty
#> not_is_empty: !queryBuilder::is_empty
#> is_null: is.na
#> not_is_null: !is.na

in_closed_range <- function(x, range) {
  x >= range[1] & x <= range[2]
}

setQueryOperators(
  "within" = queryOperator(in_closed_range),
  "not_within" = queryOperator(!in_closed_range)
)
query <- queryGroup(
  condition = "AND",
  queryRule("am", "equal", 1),
  queryRule("qsec", "within", c(10, 15)),
  queryRule("disp", "not_within", c(10, 15))
)
queryToExpr(query)
#> am == 1 & in_closed_range(qsec, c(10, 15)) & !in_closed_range(disp, 
#>     c(10, 15))