AFLUtils: AFL utility functions

AFLUtilsR Documentation

AFL utility functions

Description

Normally we don't need these functions. But in case we do, they are flexible in constructing high-order AFL expressions, e.g. AFL raw string or expressions generated in one place and used in other places with or without modification.

Methods

Public methods


Method e_to_afl()

Convert filter expression(s) to AFL filter

Usage
AFLUtils$e_to_afl(e, regex_func = "regex", ignore_case = TRUE)
Arguments
e

A list of R expression(s). If more than one expression is provided, they will be joined with logic AND.

regex_func

A string of regex function implementation, default 'regex'. Due to scidb compatiblity issue with its dependencies, the regex function from boost library may not be available Currently supported options include 'rsub', and 'regex'

ignore_case

A Boolean, default TRUE. If TRUE, ignore case in string match patterns. Otherwise, perform case-sensitive regex matches.

Returns

An AFL filter string


Method args_to_expressions()

Convert API ... args to an R expression vector (deprecated)

Some API functions include ... arg to represent arbitrary search criteria. This provides flexibility and simplifies API function signatures, but only supports limited advanced search, e.g. xxx_contains, xxx_range, xxx_not.

Eg. name_contains = 'str' => name %contains% 'str' Eg. value_range = c(1, 9) => c(value >= 1, value <= 9)

Usage
AFLUtils$args_to_expressions(..., .dots = NULL)
Arguments
...

API ellipsis args

.dots

Explicitly provide a parameter list. If not NULL, the ellipsis params are ignored

Returns

A list of AFL expressions in R


Method e()

Create a list of R expressions

The ... ellipsis arg can include arbitrary expressions, where all names are preserved in their literal forms, except for those prefixed with !! (double exclamation marks) which will be evaluated to their actual values in the calling environment.

Besides common comparison operators including ==, >, <, >=, <=, !=, there are a few special operators supported to ease AFL generation:

  • %in% semantically similar to R. a %in% !!c(1,2,3) will be translated to ⁠(a == 1 or a == 2 or a == 3)⁠

  • ⁠%like%⁠ for string regex matching.

Usage
AFLUtils$e(...)
Arguments
...

The ellipsis arg can have multiple items as expressions, but NO named items as in a named list.

Returns

A list of R expressions


Method e_merge()

Merge multiple R expressions into one

Merge an ExprsList into a single Expression so that it can be used as a FilterExpr

Usage
AFLUtils$e_merge(el, mode = "AND")
Arguments
el

A list of R expressions

mode

'AND' | 'OR'. Logical relationships when merging the expressions.

Returns

R expression


Method join_fields()

Just multple fields with sep = ','

Default behavior: paste(..., sep = sep, collapse = sep) where sep = ','

afl(...) will convert vectors to joined strings separated by ⁠,⁠. This function is useful in concatenating multiple vectors in parallel, e.g. joining a new field vector and expression vector for the apply operator.

Usage
AFLUtils$join_fields(..., sep = ",")
Arguments
...

Multiple string vectors

sep

A single character string, defaullt ",", as field separator.


Method validate_filter_expr()

Validate a filter expression

Current only report errors on:

  1. Name symbols that are not known schema fields, defined by param all_fields

  2. Non-atomic R 'values' in the expression

Usage
AFLUtils$validate_filter_expr(filter_expr, all_fields)
Arguments
filter_expr

AFL captured as a single R expression

all_fields

A list of strings as the scope of valid fields

Returns

A list object with named elements: success:bool, absent_fields: c(”), error_msgs: c(”)


Paradigm4/ArrayOpR documentation built on Dec. 11, 2023, 5:59 a.m.