insightsengineering / insightsengineering/teal.slice

[Feature Request] Enhance API and FilterState to accept arbitrary logical expr

Open
#256 1 comment 0 reactions 0 assignees View on GitHub
core enhancement
Dominant language
R
Stars
12
Forks
7
Avg merge
3d 31m
Merged PRs (30d)
1

Description

This idea from @chlebowa could replace complicated arbitrary filter expressions obtained for example from "citril".

Consider example
![image](https://user-images.githubusercontent.com/6959016/235110248-dc2ccfc1-1cff-4f76-ab36-822e01a7a1d8.png)

Which can be represented by:

```r
filter_group(
operator = "&",
filter_var(dataname = "adsl", varname = "TR01AG2", expr = grepl("Single Step Dose", TR01AG2)),
filter_var(dataname = "adsl", varname = "TRT01A", expr = !grepl("132", TRT01A))
)
```

Could be possible to nest calls within calls, for example:
```r
filter_group(
operator = "|",
filter_var(..., expr = x == "M" | x == "F" & !is.na(x)),
filter_group(
operator = "&"
filter_var(..., expr = !grepl("M", x = x) & !is.na(x)),
filter_var(...)
)
)
```

Ways to implement this:
1. Before initializing FilterState evaluate `expr` on appropriate variable and obtain `choices`, `selected`, `keep_na`, `keep_inf`; then call a `init_filter_state`. This assumes that `expr` in initial API call won't reproduced by `get_filter_state`, as `expr` isn't passed to the FilterState class.
2. Alternatively to (1) we can pass `expr` to `FilterState` and resolve it in the constructor by handing over to `set_choices` and `set_selected` in the child classes.

Key advantages:
- with above would replace filter_expr (even those complicated) - we might consider to drop `filter_expr`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.