insightsengineering / teal.modules.clinical

Provides teal modules for the standard clinical trials outputs
https://insightsengineering.github.io/teal.modules.clinical/
Other
32 stars 17 forks source link

[Bug]: surv_time error #1211

Closed jeanneyue closed 1 month ago

jeanneyue commented 2 months ago

What happened?

Hi, I tried to use tm_t_tte. It worked except for certain data somehow. When I have time=c(16.73 7.76 18.77 10.91 9.04 11.51 6.51 11.21 10.42) and all are events. It returned an error message: Error: Error applying analysis function (var - AVAL): missing value where TRUE/FALSE needed occured at (row) path: root

Would you please help? It is too hard for me to debug rtables.

Best, Jeanne

sessionInfo()

R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Denver
tzcode source: internal

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

other attached packages:
 [1] stringi_1.8.4               haven_2.5.4                
 [3] readr_2.1.5                 tidyr_1.3.1                
 [5] forcats_1.0.0               openxlsx_4.2.5.2           
 [7] fs_1.6.4                    teal.widgets_0.4.2         
 [9] teal.reporter_0.3.1         teal.osprey_0.1.16         
[11] osprey_0.1.16               dplyr_1.1.4                
[13] teal.modules.clinical_0.9.1 tern_0.9.5                 
[15] rtables_0.6.8               magrittr_2.0.3             
[17] formatters_0.5.8            teal.modules.general_0.3.0 
[19] teal.transform_0.5.0        teal_0.15.2                
[21] teal.slice_0.5.1            teal.data_0.6.0            
[23] teal.code_0.5.0             ggmosaic_0.3.3             
[25] ggplot2_3.5.1               shiny_1.8.1.1              

loaded via a namespace (and not attached):
  [1] rstudioapi_0.16.0     jsonlite_1.8.8        TH.data_1.1-2        
  [4] estimability_1.5.1    farver_2.1.2          rmarkdown_2.27       
  [7] geepack_1.3.11        vctrs_0.6.5           memoise_2.0.1        
 [10] htmltools_0.5.8.1     polynom_1.4-1         broom_1.0.6          
 [13] sass_0.4.9            bslib_0.7.0           htmlwidgets_1.6.4    
 [16] fontawesome_0.5.2     sandwich_3.1-0        emmeans_1.10.2       
 [19] plotly_4.10.4         zoo_1.8-12            cachem_1.1.0         
 [22] mime_0.12             lifecycle_1.0.4       pkgconfig_2.0.3      
 [25] colourpicker_1.3.0    Matrix_1.7-0          R6_2.5.1             
 [28] fastmap_1.2.0         rbibutils_2.2.16      digest_0.6.35        
 [31] colorspace_2.1-0      shinycssloaders_1.0.0 crosstalk_1.2.1      
 [34] labeling_0.4.3        fansi_1.0.6           httr_1.4.7           
 [37] compiler_4.4.1        sparkline_2.0         withr_3.0.0          
 [40] backports_1.5.0       logger_0.3.0          MASS_7.3-60.2        
 [43] quantreg_5.98         ggpp_0.5.7            tools_4.4.1          
 [46] zip_2.3.1             httpuv_1.6.15         shinyvalidate_0.1.3  
 [49] glue_1.7.0            nlme_3.1-164          promises_1.3.0       
 [52] grid_4.4.1            checkmate_2.3.1       generics_0.1.3       
 [55] gtable_0.3.5          tzdb_0.4.0            data.table_1.15.4    
 [58] hms_1.1.3             utf8_1.2.4            ggrepel_0.9.5        
 [61] pillar_1.9.0          stringr_1.5.1         ggExtra_0.10.1       
 [64] later_1.3.2           splines_4.4.1         tern.gee_0.1.4       
 [67] lattice_0.22-6        renv_1.0.7            survival_3.6-4       
 [70] SparseM_1.83          tidyselect_1.2.1      miniUI_0.1.1.1       
 [73] knitr_1.47            ggpmisc_0.5.6         teal.logger_0.2.0    
 [76] xfun_0.45             DT_0.33               lazyeval_0.2.2       
 [79] yaml_2.3.8            shinyWidgets_0.8.6    evaluate_0.24.0      
 [82] codetools_0.2-20      tibble_3.2.1          BiocManager_1.30.23  
 [85] cli_3.6.2             xtable_1.8-4          Rdpack_2.6           
 [88] munsell_0.5.1         jquerylib_0.1.4       Rcpp_1.0.12          
 [91] MatrixModels_0.5-3    viridisLite_0.4.2     mvtnorm_1.2-5        
 [94] scales_1.3.0          crayon_1.5.3          purrr_1.0.2          
 [97] rlang_1.1.4           cowplot_1.1.3         multcomp_1.4-25      
[100] formatR_1.14          shinyjs_2.1.0

Relevant log output

Error: Error applying analysis function (var - AVAL): missing value where TRUE/FALSE needed
    occured at (row) path: roo

Code of Conduct

Contribution Guidelines

Security Policy

edelarua commented 2 months ago

Hi @jeanneyue,

Can you provide some more details about your data so that we can help you look into the issue?

In the example below I set all records as events and used the same AVAL values that you provided and did not get an error, so the issue is likely coming from somewhere else in your data.

Thanks!!

library(teal.modules.clinical)

ADSL <- tmc_ex_adsl
ADTTE <- tmc_ex_adtte %>% head(9)
ADTTE$CNSR <- rep(0, nrow(ADTTE))
ADTTE$AVAL <- c(16.73, 7.76, 18.77, 10.91, 9.04, 11.51, 6.51, 11.21, 10.42)

arm_ref_comp <- list(
  ACTARMCD = list(
    ref = "ARM B",
    comp = c("ARM A", "ARM C")
  ),
  ARM = list(
    ref = "B: Placebo",
    comp = c("A: Drug X", "C: Combination")
  )
)

app <- init(
  data = cdisc_data(
    ADSL = ADSL,
    ADTTE = ADTTE,
    code = "
      ADSL <- tmc_ex_adsl
      ADTTE <- tmc_ex_adtte
    "
  ),
  modules = modules(
    tm_t_tte(
      label = "Time To Event Table",
      dataname = "ADTTE",
      arm_var = choices_selected(
        variable_choices(ADSL, c("ARM", "ARMCD", "ACTARMCD")),
        "ARM"
      ),
      arm_ref_comp = arm_ref_comp,
      paramcd = choices_selected(
        value_choices(ADTTE, "PARAMCD", "PARAM"),
        "OS"
      ),
      strata_var = choices_selected(
        variable_choices(ADSL, c("SEX", "BMRKR2")),
        "SEX"
      ),
      time_points = choices_selected(c(10, 12), 10),
      event_desc_var = choices_selected(
        variable_choices(ADTTE, "EVNTDESC"),
        "EVNTDESC",
        fixed = TRUE
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}
jeanneyue commented 1 month ago

After I upgraded tern from 0.9.5 to 0.9.5.9022, your code and my app worked. Thanks!