Define filtering query
query-rules.Rd
Query is configuration consisting of rules and group. Rule defines a single filtering expression whereas group is combining multiple rules (or nested groups) with the provided condition.
Arguments
- ...
Rules defined with
queryRule
function.- condition
Group condition. By default 'AND' and 'OR' are available. To set custom one use setQueryConditions.
- field
Field of the filter applied to the rule. To set custom one use setQueryOperators.
- operator
Name of the operator to be applied to the rule.
- value
(optional) Values that should be applied to the rule. Some operators, such as 'is_null', don't require any value provided.
Details
Having the example expression `a == 1 | (vs == 0 & qsec > 10)` we can distinct the following rules and groups:
Rules: - `am == 1` - related to `am` field, applies `==` operator with `1` value, - `vs == 0` - related to `vs` field, applies `==` operator with `1` value, - `qsec > 10` - related to `qsec` field, applies `>` operator with `10` value.
Groups: - `(vs == 0 & qsec > 10)` - combines two rules (`vs == 0` and `qsec > 10`) with `&` condition, - `a == 1 | (vs == 0 & qsec > 10)` - combines rule `a == 1` and group `(vs == 0 & qsec > 10)` with `|` condition.
Such query can be defined by 'queryBuilder' the following way:
queryGroup(
condition = "OR",
queryRule("am", "equal", 1)
queryGroup(
condition = "AND",
queryRule("vs", "equal", 0),
queryRule("qsec", "greater", 10)
)
)
Connection between conditions and operators names and their R-based counterparts are defined with queryBuilderConfig class.
The defined query can be then converted to filtering expression with queryToExpr function.
Examples
queryGroup(
condition = "OR",
queryRule("am", "equal", 1),
queryGroup(
condition = "AND",
queryRule("vs", "equal", 0),
queryRule("qsec", "greater", 10)
)
)
#> $condition
#> [1] "OR"
#>
#> $rules
#> $rules[[1]]
#> $rules[[1]]$id
#> [1] "am"
#>
#> $rules[[1]]$field
#> [1] "am"
#>
#> $rules[[1]]$operator
#> [1] "equal"
#>
#> $rules[[1]]$value
#> [1] 1
#>
#>
#> $rules[[2]]
#> $rules[[2]]$condition
#> [1] "AND"
#>
#> $rules[[2]]$rules
#> $rules[[2]]$rules[[1]]
#> $rules[[2]]$rules[[1]]$id
#> [1] "vs"
#>
#> $rules[[2]]$rules[[1]]$field
#> [1] "vs"
#>
#> $rules[[2]]$rules[[1]]$operator
#> [1] "equal"
#>
#> $rules[[2]]$rules[[1]]$value
#> [1] 0
#>
#>
#> $rules[[2]]$rules[[2]]
#> $rules[[2]]$rules[[2]]$id
#> [1] "qsec"
#>
#> $rules[[2]]$rules[[2]]$field
#> [1] "qsec"
#>
#> $rules[[2]]$rules[[2]]$operator
#> [1] "greater"
#>
#> $rules[[2]]$rules[[2]]$value
#> [1] 10
#>
#>
#>
#>
#>