insightsengineering / rtables

Reporting tables with R
https://insightsengineering.github.io/rtables/
Other
227 stars 49 forks source link

split_rows_by indention and split_label do not align #699

Open clarkliming opened 1 year ago

clarkliming commented 1 year ago

the label and table content do not align

example

basic_table() %>%
  split_rows_by("Species", split_label = "Species", label_pos = "topleft", indent_mod = 2L) %>%
  analyze("Sepal.Length") %>%
  build_table(iris)

gives

Species          all obs
————————————————————————
    setosa              
      Mean        5.01  
    versicolor          
      Mean        5.94  
    virginica           
      Mean        6.59 

apparently, if we have complex table structures, this can easily lead to misleading tables

session info

R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

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

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

other attached packages:
[1] rtables_0.6.2.9000    magrittr_2.0.3        formatters_0.5.1.9000

loaded via a namespace (and not attached):
 [1] compiler_4.2.2  backports_1.4.1 fastmap_1.1.0   cli_3.6.0      
 [5] tools_4.2.2     htmltools_0.5.4 grid_4.2.2      checkmate_2.1.0
 [9] digest_0.6.31   jsonlite_1.8.4  rlang_1.0.6    
Melkiades commented 1 year ago

I encountered this many times, and I think it should be that the topleft follows the indentation of the split it refers to. @gmbecker ?

gmbecker commented 1 year ago

I'm not fully convinced by this, the purpose of (that use of) the topleft is to summarize structure. I'm not convinced that it would achieve that goal better by mimicing indent modifications of the splits.

Also, as a technical matter, top left is just a text blob that gets appended to. We do some tricks to get the "indentation" to match structure, those might be able to be adapted to track cumulative indent modification, but I'm not sure how difficult that would be, and as I said above I'm not actually convinced it would be better even if it's easy.

What is the actual use case here? What is the desired outcome?