Learn R Programming

rtables (version 0.3.8)

split_cols_by: Declaring a column-split based on levels of a variable

Description

Will generate children for each subset of a categorical variable

Usage

split_cols_by(
  lyt,
  var,
  labels_var = var,
  split_label = var,
  split_fun = NULL,
  format = NULL,
  nested = TRUE,
  child_labels = c("default", "visible", "hidden"),
  extra_args = list(),
  ref_group = NULL
)

Arguments

lyt

layout object pre-data used for tabulation

var

string, variable name

labels_var

string, name of variable containing labels to be displayed for the values of var

split_label

string. Label string to be associated with the table generated by the split. Not to be confused with labels assigned to each child (which are based on the data and type of split during tabulation).

split_fun

function/NULL. custom splitting function

format

FormatSpec. Format associated with this split. Formats can be declared via strings ("xx.x") or function. In cases such as analyze calls, they can character vectors or lists of functions.

nested

boolean, Add this as a new top-level split (defining a new subtable directly under root). Defaults to FALSE

child_labels

string. One of "default", "visible", "hidden". What should the display behavior be for the labels (ie label rows) of the children of this split. Defaults to "default" which flags the label row as visible only if the child has 0 content rows.

extra_args

list. Extra arguments to be passed to the tabulation function. Element position in thte 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 ttabulation function.

ref_group

character(1) or NULL. Level of var which should be considered ref_group/reference

Value

A PreDataTableLayouts object suitable for passing to further layouting functions, and to build_table.

Examples

Run this code
# NOT RUN {
lyt <- basic_table() %>%
  split_cols_by("ARM") %>%
  analyze(c("AGE", "BMRKR2"))

build_table(lyt, ex_adsl)

# Let's look at the splits in more detail

l <- basic_table() %>% split_cols_by("ARM")
l

# add an analysis (summary)
l2 <- l %>%
    analyze(c("AGE", "COUNTRY"), afun = list_wrap_x(summary) , format = "xx.xx")
l2

build_table(l2, DM)

# By default sequentially adding layouts results in nesting
library(dplyr)
DM_MF <- DM %>% filter(SEX %in% c("M", "F")) %>% mutate(SEX = droplevels(SEX))

l3 <- basic_table() %>% split_cols_by("ARM") %>%
  split_cols_by("SEX") %>%
  analyze(c("AGE", "COUNTRY"), afun = list_wrap_x(summary), format = "xx.xx")
l3

 build_table(l3, DM_MF)

# nested=TRUE vs not
l4 <- basic_table() %>% split_cols_by("ARM") %>%
 split_rows_by("SEX", split_fun = drop_split_levels) %>%
 split_rows_by("RACE", split_fun = drop_split_levels) %>%
 analyze("AGE")

l4
build_table(l4, DM)

l5 <- basic_table() %>% split_cols_by("ARM") %>%
 split_rows_by("SEX", split_fun= drop_split_levels) %>%
 analyze("AGE") %>%
 split_rows_by("RACE", nested=FALSE, split_fun = drop_split_levels) %>%
 analyze("AGE")

l5
build_table(l5, DM)


# }

Run the code above in your browser using DataLab