Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newly introduced error when adding multiple risk difference comparisons at once #182

Open
jknizia opened this issue Mar 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@jknizia
Copy link

jknizia commented Mar 20, 2024

Description

I am working on a function that creates a Tplyr table. One parameter expects a list of character vectors, containing comparison groups that will be passed on to the add_risk_diff function of {Tplyr}. The reason why the vectors are stored in a list is that I want to allow for specifying multiple comparisons. I then add the comparisons by means of the do.call function (see reprex below). I repeat this for two table layers. This worked perfectly fine with {Tplyr} version 1.1.0, however with version 1.2.0 and above I get the following error message:

image

I add layers by using the add_layers function. The error only appears when I add both layers or only the second layer. When I add only the first layer, it works fine.

Steps to Reproduce (Bug Report Only)

Here's a reproducible example:

adae <- random.cdisc.data::cadae

# Initiate table structure
structure <- Tplyr::tplyr_table(
  adae,
  treat_var = ARM,
  where = (SAFFL == "Y" & AESER == "Y")
)

# Create table layers
layer1 <- structure |>
  Tplyr::group_count("Any SAE") |>
  Tplyr::set_distinct_by(USUBJID) 

layer2 <- structure |>
  Tplyr::group_count(vars(AESOC, AEDECOD)) |>
  Tplyr::set_distinct_by(USUBJID) |>
  Tplyr::set_nest_count(TRUE)

# Add multiple risk difference columns at once to each layer
rd_pairs <- list(c("A: Drug X", "B: Placebo"), c("A: Drug X", "C: Combination"))

layer1 <- do.call(Tplyr::add_risk_diff, args = append(list(layer = layer1), rd_pairs))
layer2 <- do.call(Tplyr::add_risk_diff, args = append(list(layer = layer2), rd_pairs))
  

# Build table
table <- structure |>
  Tplyr::add_layers(layer1, layer2) |>
  Tplyr::build() 

table

Expected behavior: My approach works with {Tplyr} versions >= 1.1.0

Actual behavior: It crashes since version 1.2.0 (Note:

Versions

Note: Session Info lists {Tplyr} version 1.2.1, but I have tried it with 1.2.0 as well - same error.

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8   
[3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.utf8    

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

other attached packages:
[1] falcon_0.1.0.9053 testthat_3.1.10   tern_0.9.3        rtables_0.6.6    
[5] magrittr_2.0.3    formatters_0.5.5 

loaded via a namespace (and not attached):
 [1] httr_1.4.5               pkgload_1.3.2            tidyr_1.3.1             
 [4] jsonlite_1.8.7           splines_4.2.2            brio_1.1.3              
 [7] assertthat_0.2.1         shiny_1.7.5              Rdpack_2.4              
[10] remotes_2.4.2            sessioninfo_1.2.2        pillar_1.9.0            
[13] backports_1.4.1          lattice_0.20-45          glue_1.6.2              
[16] digest_0.6.31            promises_1.2.0.1         rbibutils_2.2.13        
[19] checkmate_2.1.0          tfrmt_0.0.3              colorspace_2.1-0        
[22] cowplot_1.1.1            htmltools_0.5.4          httpuv_1.6.9            
[25] Matrix_1.5-1             pkgconfig_2.0.3          devtools_2.4.5          
[28] broom_1.0.5              purrr_1.0.2              xtable_1.8-4            
[31] scales_1.2.1             processx_3.8.2           later_1.3.0             
[34] timechange_0.2.0         tibble_3.2.1             generics_0.1.3          
[37] ggplot2_3.4.4            usethis_2.1.6            ellipsis_0.3.2          
[40] gtsummary_1.7.2          cachem_1.0.7             withr_3.0.0             
[43] rlistings_0.2.7          Tplyr_1.2.1              cli_3.6.2               
[46] survival_3.4-0           crayon_1.5.2             mime_0.12               
[49] memoise_2.0.1            ps_1.7.2                 fs_1.6.2                
[52] fansi_1.0.6              broom.helpers_1.14.0     forcats_1.0.0           
[55] xml2_1.3.3               pkgbuild_1.4.0           profvis_0.3.7           
[58] tools_4.2.2              prettyunits_1.1.1        lifecycle_1.0.4         
[61] stringr_1.5.1            munsell_0.5.0            callr_3.7.3             
[64] random.cdisc.data_0.3.14 compiler_4.2.2           rlang_1.1.3             
[67] grid_4.2.2               gt_0.9.0                 rstudioapi_0.14         
[70] htmlwidgets_1.6.1        miniUI_0.1.1.1           gtable_0.3.3            
[73] R6_2.5.1                 lubridate_1.9.3          knitr_1.42              
[76] dplyr_1.1.4              fastmap_1.1.1            utf8_1.2.4              
[79] rprojroot_2.0.3          desc_1.4.2               stringi_1.7.12          
[82] Rcpp_1.0.10              vctrs_0.6.5              tidyselect_1.2.0        
[85] xfun_0.37                urlchecker_1.0.1   

Thanks for your help!

@mstackhouse mstackhouse added the bug Something isn't working label Apr 8, 2024
@mstackhouse
Copy link
Contributor

Adding a reprex of the issue:

library(tidyverse)
library(haven)
library(Tplyr)

adae <- haven::read_xpt(url("https://github.com/phuse-org/TestDataFactory/raw/main/Updated/TDF_ADaM/adae.xpt"))

# Create the Tplyr Table
t <- tplyr_table(adae, TRTA) %>%
  add_layer(
    group_count(vars(AEBODSYS, AEDECOD)) %>% 
      set_distinct_by(USUBJID) %>% 
      # Create nested formatting
      add_risk_diff(
        c('Xanomeline High Dose', 'Placebo'),
        c('Xanomeline Low Dose', 'Placebo')
      ) 
  ) 

# Build the Tplyr table to get the data
# Suppress warning messages from risk difference calculations
t_df <- t %>% build()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants