insightsengineering / teal

Exploratory Web Apps for Analyzing Clinical Trial Data
https://insightsengineering.github.io/teal/
Other
181 stars 39 forks source link

[Bug]: module_specific filter doesn't work due to datanames returns length of 2 #1104

Closed donyunardi closed 8 months ago

donyunardi commented 8 months ago

What happened?

A bug happened!

Code ```r Sys.setenv(TEAL.LOG_LEVEL = "TRACE") library(teal.logger) library(teal.modules.clinical) ADSL <- teal.modules.clinical::tmc_ex_adsl ADAE <- teal.modules.clinical::tmc_ex_adae ADTTE <- teal.modules.clinical::tmc_ex_adtte app <- init( data = cdisc_data( ADSL = ADSL, ADAE = ADAE, ADTTE = ADTTE ), modules = modules( tm_t_summary( label = "Demographic Table", dataname = "ADSL", arm_var = choices_selected(choices = c("ARM", "ARMCD"), selected = "ARM"), summarize_vars = choices_selected( choices = c("SEX", "RACE", "BMRKR2", "EOSDY", "DCSREAS", "AGE"), selected = c("SEX", "RACE") ) ), tm_t_events( label = "AE Table", dataname = "ADAE", arm_var = choices_selected(choices = c("ARM", "ARMCD"), selected = "ARM"), hlt = choices_selected( choices = variable_choices(ADAE, c("AEBODSYS", "AESOC")), selected = "AEBODSYS" ), llt = choices_selected( choices = variable_choices(ADAE, c("AETERM", "AEDECOD")), selected = c("AEDECOD") ) ), tm_g_km( label = "KM Plot", dataname = "ADTTE", arm_var = choices_selected(choices = c("ARM", "ARMCD", "ACTARMCD"), selected = "ARM"), paramcd = choices_selected(choices = value_choices(ADTTE, "PARAMCD", "PARAM"), selected = "OS"), strata_var = choices_selected(variable_choices(ADSL, c("SEX", "BMRKR2")), NULL), facet_var = choices_selected(variable_choices(ADSL, c("SEX", "BMRKR2")), NULL), plot_height = c(600L, 400L, 5000L), ) ), header = tags$h1("PHUSE US Connect 2024 teal Workshop"), filter = teal_slices( teal_slice("ADSL", "SAFFL", id = "saffl", selected = "Y", fixed = TRUE, anchored = TRUE), teal_slice("ADAE", "AESER", anchored = TRUE), teal_slice("ADAE", id = "aerel", expr = "AEREL == 'Y' & AETOXGR %in% c('3', '4', '5')", title = "Grade 3+ Related Events"), teal_slice("ADSL", "SEX", id = "sex", fixed = TRUE), teal_slice("ADSL", id = "age", expr = "AGE >= 18 & AGE <= 30", title = "Young Adult"), module_specific = TRUE, mapping = list( "Demographic Table" = c("saffl"), "AE Table" = c("saffl", "aerel"), global_filters = c("sex", "age") ), count_type = "all" ) ) shinyApp(app$ui, app$server) ```

The above code can't be run when I set module_specific = TRUE during filter creation and got this error message:

image

The problem is on this line: https://github.com/insightsengineering/teal/blob/91e000d7094389b41ec87ae5c7d98537182c0085/R/module_teal.R#L189

For tm_t_events, modules$datanames will return vector with length of 2: https://github.com/insightsengineering/teal.modules.clinical/blob/main/R/tm_t_events.R#L568

Therefore, the if statement will fail because modules$datanames returns "ADSL" and "ADAE".

Here's an illustration:

x <- c("ADSL", "ADAE")
if(is.null(x) || x == "all") print("hello")
#> Error in is.null(x) || x == "all": 'length = 2' in coercion to 'logical(1)'

Created on 2024-02-19 with reprex v2.0.2

sessionInfo()

R version 4.3.2 (2023-10-31)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.6.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] teal_0.15.0                       teal.modules.clinical_0.8.16.9093 tern_0.9.3                       
 [4] rtables_0.6.6.9006                magrittr_2.0.3                    formatters_0.5.5.9007            
 [7] teal.transform_0.5.0              teal.logger_0.1.3.9011            testthat_3.1.10                  
[10] teal.slice_0.5.0.9001             teal.data_0.5.0                   teal.code_0.5.0.9003             
[13] shiny_1.8.0                      

loaded via a namespace (and not attached):
  [1] rstudioapi_0.15.0       jsonlite_1.8.8          TH.data_1.1-2           estimability_1.4.1      rmarkdown_2.25         
  [6] geepack_1.3.9           fs_1.6.3                vctrs_0.6.5             memoise_2.0.1           htmltools_0.5.7        
 [11] forcats_1.0.0           usethis_2.2.2           broom_1.0.5             sass_0.4.8              bslib_0.6.1            
 [16] htmlwidgets_1.6.4       desc_1.4.2              fontawesome_0.5.2       sandwich_3.0-2          emmeans_1.8.8          
 [21] plotly_4.10.2           zoo_1.8-12              cachem_1.0.8            mime_0.12               lifecycle_1.0.4        
 [26] teal.widgets_0.4.2.9004 pkgconfig_2.0.3         Matrix_1.6-1.1          R6_2.5.1                fastmap_1.1.1          
 [31] rbibutils_2.2.15        digest_0.6.33           colorspace_2.1-0        shinycssloaders_1.0.0   ps_1.7.5               
 [36] rprojroot_2.0.4         pkgload_1.3.3           fansi_1.0.6             httr_1.4.7              compiler_4.3.2         
 [41] remotes_2.4.2.1         withr_2.5.2             backports_1.4.1         logger_0.2.2            pkgbuild_1.4.2         
 [46] R.utils_2.12.3          MASS_7.3-60             sessioninfo_1.2.2       tools_4.3.2             httpuv_1.6.13          
 [51] shinyvalidate_0.1.3     clipr_0.8.0             R.oo_1.25.0             glue_1.6.2              callr_3.7.3            
 [56] nlme_3.1-163            R.cache_0.16.0          promises_1.2.1          grid_4.3.2              checkmate_2.3.1        
 [61] generics_0.1.3          gtable_0.3.4            R.methodsS3_1.8.2       tidyr_1.3.0             data.table_1.14.10     
 [66] utf8_1.2.4              pillar_1.9.0            stringr_1.5.1           later_1.3.2             splines_4.3.2          
 [71] tern.gee_0.1.3.9001     dplyr_1.1.4             lattice_0.21-9          survival_3.5-7          tidyselect_1.2.0       
 [76] miniUI_0.1.1.1          knitr_1.44              xfun_0.40               devtools_2.4.5          brio_1.1.3             
 [81] stringi_1.8.3           lazyeval_0.2.2          yaml_2.3.7              shinyWidgets_0.8.0      evaluate_0.22          
 [86] codetools_0.2-19        tibble_3.2.1            cli_3.6.2               xtable_1.8-4            Rdpack_2.5             
 [91] munsell_0.5.0           processx_3.8.2          jquerylib_0.1.4         styler_1.10.2           Rcpp_1.0.11            
 [96] teal.reporter_0.3.0     ellipsis_0.3.2          ggplot2_3.4.4           prettyunits_1.2.0       profvis_0.3.8          
[101] urlchecker_1.0.1        reprex_2.0.2            viridisLite_0.4.2       mvtnorm_1.2-2           scales_1.3.0           
[106] purrr_1.0.2             crayon_1.5.2            rlang_1.1.2             multcomp_1.4-25         formatR_1.14           
[111] shinyjs_2.1.0

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy

donyunardi commented 8 months ago

One possible way to solve this is to wrap all() on modules$datanames == "all"

datanames <- if (is.null(modules$datanames) || all(modules$datanames == "all")) {

I did this locally and the code can now run. If this finding is correct, let's do a patch release.