insightsengineering / insightsengineering/teal.modules.clinical

Fix the readibility of validate reactives

Open
#545 1 comment 0 reactions 0 assignees View on GitHub
core sme
Dominant language
R
Stars
42
Forks
22
Avg merge
22m
Merged PRs (30d)
1

Description

Currently in almost all tmc modules we have `validate <- reactive(...)` which contains around ~100 lines of code to validate inputs, length of variables, number of arm levels, rows etc. There is nothing wrong with long validate but it involves `data[[]]` and `quo[["ADSL"]]` and `merged()$columns_source$`. Because of this merge get even more complicated as it require so much focus (read the validate in tm_t_logistic below)

https://github.com/insightsengineering/teal.modules.clinical/blob/e225371a7cc9c5eb27fad06798747a06f19862c7/R/tm_t_logistic.R#L533

Following are confusing:
- having two source of data in the `data` (filtered data) and in the `merged_q` (ANL).
- except `merged_q` we have also reactive output from `merge_expression_module` where we need `$columns_source$`
- `$columns_source$` is a hard bit, because values of the `$columns_source` are the (renamed) names in the `ANL` and names of the `$columns_source$` are the names in the original (filtered) dataset.
- Also there are some duplicated valiation in these `validate` reactives

My opinion is that this validation doesn't have to be a separate reactive but instead we can replace stopifnot in the `template_`

Contributor guide

Open the contributing guide

Research direction

Read the validate reactive in R/tm_t_logistic.R around line 533, focusing on the data, merged_q, and merge_expression_module sources and the duplicated validation described in the issue. Compare this with the referenced template_ code; done means the validation is less confusing and duplicated checks are removed without losing input, length, arm-level, or row validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.