Skip to content

Add picks variable selection to ae_oview module#331

Open
osenan wants to merge 40 commits into
redesign_extraction@mainfrom
oriol_ae_oview_picks@main
Open

Add picks variable selection to ae_oview module#331
osenan wants to merge 40 commits into
redesign_extraction@mainfrom
oriol_ae_oview_picks@main

Conversation

@osenan

@osenan osenan commented Mar 12, 2026

Copy link
Copy Markdown

Pull Request

This partially closes #330

I based my changes in this PR.

Please compare both modules with this example app (requires to have teal.picks installed, osprey)

library("teal")
library("teal.picks")
devtools::load_all()

data <- teal_data() %>%
  within({
    library(dplyr)
    ADSL <- teal.data::rADSL
    ADAE <- teal.data::rADAE
    .add_event_flags <- function(dat) {
      dat <- dat %>%
        mutate(
          TMPFL_SER = AESER == "Y",
          TMPFL_REL = AEREL == "Y",
          TMPFL_GR5 = AETOXGR == "5",
          AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X"),
          AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")
        )
      labels <- c(
        "Serious AE", "Related AE", "Grade 5 AE",
        "AE related to A: Drug X", "AE related to B: Placebo"
      )
      cols <- c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2")
      for (i in seq_along(labels)) {
        attr(dat[[cols[i]]], "label") <- labels[i]
      }
      dat
    }
    ADAE <- .add_event_flags(ADAE)
  })

join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_g_ae_oview(
      label = "Common AE (picks)",
      flag_var_anl = teal.picks::picks(
        teal.picks::datasets("ADAE"),
        teal.picks::variables(
           choices = c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2"),
          selected = "TMPFL_SER"
        )
      ),
      arm_var = teal.picks::picks(
        teal.picks::datasets("ADSL"),
        teal.picks::variables(
          choices = teal.picks::is_categorical(min.len = 2),
          selected = "ACTARMCD"
        )
      ),
      plot_height = c(600, 200, 2000)
    ),
    # Default method (old) for comparison
    tm_g_ae_oview(
      label = "Common AE (default)",
      dataname = "ADAE",
      flag_var_anl = teal.transform::choices_selected(
        selected = "AEREL1",
        choices = teal.transform::variable_choices(
          data[["ADAE"]],
          c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2")
        )
      ),
      arm_var = teal.transform::choices_selected(
        selected = "ACTARMCD",
        choices = c("ACTARM", "ACTARMCD")
      ),
      plot_height = c(600, 200, 2000)
    )
  )
)

shinyApp(app$ui, app$server)

I refactored the tm_g_ae_oview module to create a generic, keep the default for teal.transform and add a method for picks variable selection. The module works as expected and setting the variables is better with picks. The issue reported in the similar PR on the plot dimensions is fixed if we set the plot dimensions in the module. The ui of the picks ui components is different and it breaks, in my opinion, the color pattern of the teal app.

image image

Here the teal.transform module

image image

I added simple tests for the module as well

@osenan osenan added the core label Mar 12, 2026
@github-actions

github-actions Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor


🎉 Thank you for your contribution! Before this PR can be accepted, we require that you read and agree to our Contributor License Agreement.
You can digitally sign the CLA by posting a comment on this Pull Request in the format shown below. This agreement will apply to this PR as well as all future contributions on this repository.


I have read the CLA Document and I hereby sign the CLA


osenan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@osenan osenan requested a review from a team March 12, 2026 11:38
@osenan

osenan commented Mar 12, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@osenan osenan marked this pull request as draft March 12, 2026 14:59
@osenan

osenan commented Mar 12, 2026

Copy link
Copy Markdown
Author

Changed to draft as I need to fix:

  • Checks
  • Plot
  • Decorators

@averissimo averissimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some preliminary comments.

  • I believe this is a good case for only keeping 1 version of the module logic. (We can convert directly from choices_selected -> variables())
  • I see that you're using picks(), consider using variables() instead for arm_var and flag_var_anl
    • And then create picks() inside the tm_g_ae_oview() call

Comment thread R/tm_g_ae_oview.R Outdated
Comment thread DESCRIPTION Outdated
Comment thread R/tm_g_ae_oview_picks.R Outdated
Comment thread R/tm_g_ae_oview.R Outdated
Comment thread R/tm_g_ae_oview_picks.R Outdated
Comment thread R/tm_g_ae_oview_picks.R Outdated
Comment thread R/tm_g_ae_oview_picks.R Outdated
Comment thread R/tm_g_ae_oview_picks.R Outdated
Comment thread R/tm_g_ae_oview_picks.R Outdated
Comment thread R/tm_g_ae_oview_picks.R Outdated
osenan and others added 4 commits March 16, 2026 12:31
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>
@osenan

osenan commented Mar 16, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@osenan osenan marked this pull request as ready for review March 17, 2026 06:45
@osenan

osenan commented Mar 17, 2026

Copy link
Copy Markdown
Author

The plot and decorator I will handle in a separate issue finally

@github-actions

github-actions Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

badge

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  -------------------------------------------------
R/tm_g_ae_oview.R                  271     210  22.51%   90-94, 98-102, 169-402
R/tm_g_ae_sub.R                    288     288  0.00%    60-379
R/tm_g_butterfly.R                 371     371  0.00%    125-534
R/tm_g_decorate.R                   42      42  0.00%    17-91
R/tm_g_events_term_id_picks.R      305     305  0.00%    23-406
R/tm_g_events_term_id.R            289     247  14.53%   131-407
R/tm_g_heat_bygrade.R              293     293  0.00%    136-459
R/tm_g_patient_profile.R           691     691  0.00%    159-913
R/tm_g_spiderplot.R                322     322  0.00%    100-464
R/tm_g_swimlane.R                  332     288  13.25%   65, 124-459
R/tm_g_waterfall.R                 414     374  9.66%    80-82, 141-569
R/utils_picks.R                     90      37  58.89%   18, 29-30, 55-76, 102, 106, 122-126, 146, 152-156
R/utils.R                           64      59  7.81%    31-73, 107-201
R/zzz.R                              3       3  0.00%    4-7
TOTAL                             3775    3530  6.49%

Diff against main

Filename                         Stmts    Miss  Cover
-----------------------------  -------  ------  --------
R/tm_g_ae_oview.R                  +46     -15  +22.51%
R/tm_g_events_term_id_picks.R     +305    +305  +100.00%
R/tm_g_events_term_id.R            +18     -24  +14.53%
R/tm_g_swimlane.R                  -13     -57  +13.25%
R/tm_g_waterfall.R                 -15     -55  +9.66%
R/utils_picks.R                    +90     +37  +58.89%
R/utils.R                          -21     -21  +1.93%
TOTAL                             +410    +170  +6.34%

Results for commit: e8572b5

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions

github-actions Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Unit Tests Summary

 1 files  ±0   5 suites  +1   0s ⏱️ ±0s
17 tests +4  12 ✅ +4  5 💤 ±0  0 ❌ ±0 
49 runs  +9  44 ✅ +9  5 💤 ±0  0 ❌ ±0 

Results for commit e8572b5. ± Comparison against base commit 80256d0.

♻️ This comment has been updated with latest results.

osenan and others added 6 commits March 17, 2026 15:31
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>

@averissimo averissimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to be merged as it works as expected.

I have one last ask that both me and @m7pr have been doing in tmc and it also makes sense here.

Instead of S3 class we can just convert choices_selected in the body of the function, in essence support both without the overhead of S3.

Check this R/tm_t_pp_basic_info.R: https://github.com/insightsengineering/teal.modules.clinical/pull/1476/changes#diff-d50ab07375ab0f048cc866c3f6c0a0e7ed77c779483742bd3eebf05156f2a677

Comment thread R/tm_g_ae_oview.R Outdated
Comment thread tests/testthat/test-tm_g_ae_oview.R
@osenan osenan requested a review from averissimo April 8, 2026 09:25

@averissimo averissimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's almost ready! 👍

My main request is about the default arguments, in this package it might be better to leave them <missing>.

The second main comment here is about the implementation of the conversion. I would prefer to keep this only *if really needed* as it breaks with best practices of R and this project.

I understand the requirements for the util, but maybe we can find a middle ground, see my suggestion and we can then apply "upstrean" on tmc

Comment thread R/tm_g_ae_oview.R Outdated
Comment thread R/utils.R Outdated
Comment thread R/tm_g_ae_oview.R Outdated
Comment thread R/tm_g_ae_oview.R
Comment thread R/utils.R Outdated
Comment thread R/tm_g_ae_oview.R Outdated
osenan and others added 2 commits April 9, 2026 16:44
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>

@averissimo averissimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Seems fine by me

Comment thread R/utils.R Outdated
osenan and others added 2 commits April 10, 2026 15:17
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Signed-off-by: Oriol Senan  <35930244+osenan@users.noreply.github.com>
Comment thread R/tm_g_ae_oview.R Outdated
Comment on lines +55 to +56
#' arm_var = teal.picks::variables(
#' choices = dplyr::starts_with("ACTARM"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not prefix functions in examples nor vignettes.
Only prefix in tests and in the code/implemetnation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you move teal.picks in DESCRIPTION from Imports to Depends, you will not need to prefix those functions for the examples to work. As you didn't need to prefix teal.transform functions

Comment thread R/tm_g_ae_oview.R
Comment on lines +74 to +75
arm_var,
flag_var_anl,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know @averissimo suggested to drop default values, but we do have default values and the checks in tmc :P

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is not critical

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the default was empty so I will keep it empty

Comment thread R/tm_g_ae_oview.R Outdated
Comment on lines +92 to +106
if (isTRUE(attr(arm_var$variables, "multiple"))) {
warning(
"`arm_var` accepts only a single variable selection. ",
"Forcing `teal.picks::variables(multiple)` to FALSE."
)
attr(arm_var$variables, "multiple") <- FALSE
}

if (isTRUE(attr(flag_var_anl$variables, "multiple"))) {
warning(
"`flag_var_anl` accepts only a single variable selection. ",
"Forcing `teal.picks::variables(multiple)` to FALSE."
)
attr(flag_var_anl$variables, "multiple") <- FALSE
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this possible to make it a wrapper, and reuse in all modules in this package? You could keep this wrapper in the main feature branch and reuse in single branches for specific modules.

Comment thread R/utils.R Outdated
Comment on lines +250 to +252
arg <- rlang::ensym(arg)
arg_name <- as.character(arg)
arg <- rlang::eval_tidy(arg, env = envir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible use base R instead of rlang

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also rlang was not in imports/depends so you get this warning in R CMD CHECK
https://github.com/insightsengineering/teal.osprey/actions/runs/24245023719/job/70788946164?pr=331#step:44:98

Comment thread tests/testthat/test-tm_g_ae_oview.R Outdated
)
})

testthat::it("fails when flag_var_anl is neiter picks or choices_selected", {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we agreed to add testthat:: prefix for all tests for all functions besides it function, as it collideas with some namespace. check other packages in teal family to see that it is barely prefixed

Comment thread DESCRIPTION Outdated
teal.code (>= 0.7.0),
teal.data (>= 0.8.0),
teal.logger (>= 0.4.0),
teal.picks (>= 0.1.0),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

teal.transform is in the Depends, and teal.picks is a substitute, so should also be in the Depends. the same we did in tmc

@m7pr m7pr self-assigned this Apr 14, 2026
@osenan osenan changed the base branch from main to redesign_extraction@main June 20, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Allow modules to use teal.picks

4 participants