rtables icon indicating copy to clipboard operation
rtables copied to clipboard

col_info setter and getter refactoring

Open shajoezhu opened this issue 1 year ago • 2 comments

post-processing for col_info to be more flexible, for example adding total N's

shajoezhu avatar Oct 18 '23 05:10 shajoezhu

These exist.

> col_info
standardGeneric for "col_info" defined from package "rtables"

function (obj) 
standardGeneric("col_info")
<bytecode: 0x7fde00810158>
<environment: 0x7fde00809660>
Methods may be defined for arguments: obj
Use  showMethods(col_info)  for currently available ones.
> `col_info<-`
standardGeneric for "col_info<-" defined from package "rtables"

function (obj, value) 
standardGeneric("col_info<-")
<bytecode: 0x7fde0083a610>
<environment: 0x7fde00827b50>
Methods may be defined for arguments: obj, value
Use  showMethods(col_info<-)  for currently available ones.

gmbecker avatar Oct 27 '23 18:10 gmbecker

df <- data.frame(cat =c( "really long thing its so long",
                        "reasonable thing",
                        "short"),
                 value = c(6, 3, 10))

lyt <- basic_table(show_colcounts = TRUE) %>%
    split_rows_by("cat", section_div = " ") %>%
    analyze("value")



tbl <- build_table(lyt, df)
tbl

gives

                                all obs
                                 (N=3) 
———————————————————————————————————————
really long thing its so long          
  Mean                           6.00  
                                       
reasonable thing                       
  Mean                           3.00  
                                       
short                                  
  Mean                           10.00 

and then

col_counts(tbl) <- 17L
tbl

gives

                                all obs
                                (N=17) 
———————————————————————————————————————
really long thing its so long          
  Mean                           6.00  
                                       
reasonable thing                       
  Mean                           3.00  
                                       
short                                  
  Mean                           10.00 

gmbecker avatar Nov 15 '23 20:11 gmbecker