insightsengineering / chevron

Standard TLGs For Clinical Trials Reporting
https://insightsengineering.github.io/chevron/
Other
11 stars 1 forks source link

MNG01: when the data is split by PARAM, the levels of x_var (AVISIT) should not be retained as they were in entire dataset #785

Open kathrinflunkert opened 14 hours ago

kathrinflunkert commented 14 hours ago

Example:

library(chevron)
library(dplyr)

data <- syn_data

data$adlb <- data$adlb %>% 
  filter((AVISIT == "BASELINE" & PARAMCD == "IGA") | (AVISIT %in% c("BASELINE", "WEEK 1 DAY 8") & PARAMCD == "CRP"))

run(mng01, data, dataset = "adlb")

Result: For the parameter that only has baseline data the table is not aligned with the plot and shows the second visit with NAs:

image

As per @yurovska a fix can look like this: The following line in mng01_main

data_ls <- split(df, df$PARAM, drop = TRUE)

is to be updated to

data_ls <- split(df, df$PARAM, drop = TRUE) %>%
    lapply(function(data) {
      # Drop unused levels of `x_var` from each PARAM after splitting
      data[[x_var]] <- droplevels(data[[x_var]])
      return(data)
    })
BFalquet commented 14 hours ago

Please provide sessionInfo() information

yurovska commented 13 hours ago

Please provide sessionInfo() information

R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
[1] tlg_ctassets_0.0.0.9000

loaded via a namespace (and not attached):
 [1] gtable_0.3.4          ggplot2_3.5.0         formatters_0.5.8      processx_3.8.2        lattice_0.22-6        callr_3.7.3           vctrs_0.6.4          
 [8] tools_4.3.3           Rdpack_2.5            ps_1.7.5              generics_0.1.3        tibble_3.2.1          fansi_1.0.5           R.oo_1.25.0          
[15] pkgconfig_2.0.3       Matrix_1.6-5          checkmate_2.2.0       desc_1.4.2            assertthat_0.2.1      lifecycle_1.0.3       farver_2.1.1         
[22] compiler_4.3.3        stringr_1.5.0         brio_1.1.3            munsell_0.5.0         rlistings_0.2.9       htmltools_0.5.6.1     yaml_2.3.7           
[29] pillar_1.9.0          crayon_1.5.2          tidyr_1.3.0           R.utils_2.12.2        tern_0.9.4            rtables_0.6.9         nestcolor_0.1.1      
[36] tidyselect_1.2.0      digest_0.6.33         stringi_1.7.12        dplyr_1.1.3           purrr_1.0.2           labeling_0.4.3        arrow_13.0.0.1       
[43] forcats_1.0.0         splines_4.3.3         cowplot_1.1.3         rprojroot_2.0.3       fastmap_1.1.1         grid_4.3.3            colorspace_2.1-0     
[50] cli_3.6.2             magrittr_2.0.3        survival_3.6-4        pkgbuild_1.4.2        utf8_1.2.3            broom_1.0.5           withr_2.5.1          
[57] prettyunits_1.2.0     scales_1.3.0          backports_1.4.1       citril_0.1.12         bit64_4.0.5           citril.metadata_0.1.7 bit_4.0.5            
[64] R.methodsS3_1.8.2     rbibutils_2.2.15      testthat_3.2.0        chevron_0.2.6         rlang_1.1.1           oceanflow_1.1.0.0001  glue_1.6.2           
[71] BiocManager_1.30.22   renv_1.0.3            pkgload_1.3.3         jsonlite_1.8.7        rstudioapi_0.15.0     R6_2.5.1              dunlin_0.1.7
kathrinflunkert commented 6 hours ago

I learnt today that this has apparently already been fixed in the latest version of g_lineplot which we are not using yet right now. @BFalquet Should I just close this issue here? I can't test the latest version right now, but I am sure you are right that it has already been fixed.