Skip to contents

Add or remove bold and italic styling in the cells of a table. The remove_*() functions remove all bold or italic styling by default; pass columns and rows to limit them.

Usage

modify_bold(x, columns, rows)

modify_italic(x, columns, rows)

remove_bold(x, columns = everything(), rows = TRUE)

remove_italic(x, columns = everything(), rows = TRUE)

Arguments

x

(ltsummary)
An ltsummary object.

columns

(selector)
Columns of x$table_body.

rows

(predicate expression)
Expression selecting rows of x$table_body, e.g. row_type == "label". Used for footnotes, formatting functions, missing symbols, indentation and text formatting. Default is NULL, which selects every row (or, for a footnote, places it in the column header). See the section below.

Value

An ltsummary object.

rows argument

The rows argument is a predicate expression that selects the rows the styling applies to. It is evaluated in x$table_body, so its column names are available as variables, and it must give a logical vector. To style the rows of the age variable pass rows = variable == "age"; to style the variable label rows pass rows = row_type == "label". A logical vector, a vector of row numbers or a function of table_body are also accepted.

Objects from the calling environment can be used in the expression, e.g. rows = variable == vars[1], as long as they do not share a name with a column of x$table_body. The expression is stored, not its result, and resolved when the table is printed, so it survives later changes to the table such as remove_row_type().

Examples

# Example 1 ----------------------------------
tbl <- trial |>
  tbl_summary(include = grade) |>
  modify_bold(columns = label, rows = row_type == "label") |>
  modify_italic(columns = label, rows = row_type == "level")
tbl
# Example 2 ---------------------------------- tbl |> remove_bold(columns = label, rows = row_type == "label") |> remove_italic(columns = label, rows = row_type == "level")
# Example 3 ---------------------------------- # bold the cells of one arm in the rows of one variable trial |> tbl_summary(by = trt, include = c(age, grade)) |> modify_bold(columns = stat_2, rows = variable == "grade")