Skip to contents

Some variables are inherently grouped and should be reported together. add_variable_group_header() adds a header above a group of variables and indents the group.

Usage

add_variable_group_header(x, header, variables, indent = 4L)

Arguments

x

(ltsummary)
An ltsummary object whose first shown column is the label column.

header

(string)
The header to place above the variable group.

variables

(selector)
Variables to group. The selected variables should appear consecutively in the table; the header is inserted above the first of them.

indent

(integer)
Number of spaces every row of the group is indented by. Default is 4L.

Value

An ltsummary object.

Details

The function inserts a row with row_type = "variable_group" into x$table_body and indents every row of the selected variables. It does not combine with every other function; bold_labels(), for example, bolds the variable labels inside the group but not the inserted header.

Examples

# Example 1 ----------------------------------
set.seed(11234)
data.frame(
  exclusion_age = sample(c(TRUE, FALSE), 20, replace = TRUE),
  exclusion_mets = sample(c(TRUE, FALSE), 20, replace = TRUE),
  exclusion_physician = sample(c(TRUE, FALSE), 20, replace = TRUE)
) |>
  tbl_summary(
    label = list(exclusion_age = "Age",
                 exclusion_mets = "Metastatic Disease",
                 exclusion_physician = "Physician")
  ) |>
  add_variable_group_header(
    header = "Exclusion Reason",
    variables = starts_with("exclusion_")
  ) |>
  modify_caption("**Study Exclusion Criteria**")
# Example 2 ---------------------------------- # two grouped sections in one table trial |> tbl_summary(include = c(age, marker, stage, grade), missing = "no") |> add_variable_group_header("Measures", variables = c(age, marker)) |> add_variable_group_header("Tumor Facts", variables = c(stage, grade))