Skip to contents

Add a virtual "overall" level to split

Usage

add_overall_level(
  valname = "Overall",
  label = valname,
  extra_args = list(),
  first = TRUE,
  trim = FALSE
)

Arguments

valname

(string)
value to be assigned to the implicit all-observations split level. Defaults to "Overall".

label

(string)
a label (not to be confused with the name) for the object/structure.

extra_args

(list)
extra arguments to be passed to the tabulation function. Element position in the list corresponds to the children of this split. Named elements in the child-specific lists are ignored if they do not match a formal argument of the tabulation function.

first

(flag)
whether the implicit level should appear first (TRUE) or last (FALSE). Defaults to TRUE.

trim

(flag)
whether splits corresponding with 0 observations should be kept when tabulating.

Value

A closure suitable for use as a splitting function (splfun) when creating a table layout.

Examples

lyt <- basic_table() %>%
  split_cols_by("ARM", split_fun = add_overall_level("All Patients",
    first = FALSE
  )) %>%
  analyze("AGE")

tbl <- build_table(lyt, DM)
tbl
#>        A: Drug X   B: Placebo   C: Combination   All Patients
#> —————————————————————————————————————————————————————————————
#> Mean     34.91       33.02          34.57           34.22    

lyt2 <- basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("RACE",
    split_fun = add_overall_level("All Ethnicities")
  ) %>%
  summarize_row_groups(label_fstr = "%s (n)") %>%
  analyze("AGE")
lyt2
#> A Pre-data Table Layout
#> 
#> Column-Split Structure:
#> ARM (lvls) 
#> 
#> Row-Split Structure:
#> RACE (lvls) -> AGE (** analysis **) 
#> 

tbl2 <- build_table(lyt2, DM)
tbl2
#>                                                  A: Drug X      B: Placebo    C: Combination
#> ————————————————————————————————————————————————————————————————————————————————————————————
#> All Ethnicities (n)                             121 (100.0%)   106 (100.0%)    129 (100.0%) 
#>   Mean                                             34.91          33.02           34.57     
#> ASIAN (n)                                        79 (65.3%)     68 (64.2%)      84 (65.1%)  
#>   Mean                                             34.20          32.68           34.63     
#> BLACK OR AFRICAN AMERICAN (n)                    28 (23.1%)     24 (22.6%)      27 (20.9%)  
#>   Mean                                             34.68          31.71           34.00     
#> WHITE (n)                                        14 (11.6%)     14 (13.2%)      18 (14.0%)  
#>   Mean                                             39.36          36.93           35.11     
#> AMERICAN INDIAN OR ALASKA NATIVE (n)              0 (0.0%)       0 (0.0%)        0 (0.0%)   
#>   Mean                                               NA             NA              NA      
#> MULTIPLE (n)                                      0 (0.0%)       0 (0.0%)        0 (0.0%)   
#>   Mean                                               NA             NA              NA      
#> NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER (n)     0 (0.0%)       0 (0.0%)        0 (0.0%)   
#>   Mean                                               NA             NA              NA      
#> OTHER (n)                                         0 (0.0%)       0 (0.0%)        0 (0.0%)   
#>   Mean                                               NA             NA              NA      
#> UNKNOWN (n)                                       0 (0.0%)       0 (0.0%)        0 (0.0%)   
#>   Mean                                               NA             NA              NA