Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

modify_table_styling

Modify Table Styling


Description

This is a function meant for advanced users to gain more control over the characteristics of the resulting gtsummary table by directly modifying .$table_styling

Usage

modify_table_styling(
  x,
  columns,
  rows = NULL,
  label = NULL,
  spanning_header = NULL,
  hide = NULL,
  footnote = NULL,
  footnote_abbrev = NULL,
  align = NULL,
  missing_symbol = NULL,
  fmt_fun = NULL,
  text_format = NULL,
  undo_text_format = FALSE,
  text_interpret = c("md", "html"),
  cols_merge_pattern = NULL
)

Arguments

x

gtsummary object

columns

vector or selector of columns in x$table_body

rows

predicate expression to select rows in x$table_body. Can be used to style footnote, formatting functions, missing symbols, and text formatting. Default is NULL. See details below.

label

string of column label(s)

spanning_header

string with text for spanning header

hide

logical indicating whether to hide column from output

footnote

string with text for footnote

footnote_abbrev

string with abbreviation definition, e.g. "CI = Confidence Interval"

align

string indicating alignment of column, must be one of c("left", "right", "center")

missing_symbol

string indicating how missing values are formatted.

fmt_fun

function that formats the statistics in the columns/rows in columns= and rows=

text_format

string indicated which type of text formatting to apply to the rows and columns. Must be one of c("bold", "italic", "indent")

undo_text_format

rarely used. Logical that undoes the indent, bold, and italic styling when TRUE

text_interpret

string, must be one of "md" or "html"

cols_merge_pattern

glue-syntax string indicating how to merge columns in x$table_body. For example, to construct a confidence interval use "{conf.low}, {conf.high}". The first column listed in the pattern string must match the single column name passed in columns=.

Details

Review the gtsummary definition vignette for information on .$table_styling objects.

rows argument

The rows argument accepts a predicate expression that is used to specify rows to apply formatting. The expression must evaluate to a logical when evaluated in x$table_body. For example, to apply formatting to the age rows pass rows = variable == "age". A vector of row numbers is NOT acceptable.

A couple of things to note when using the rows= argument.

  1. You can use saved objects to create the predicate argument, e.g. rows = variable == letters[1].

  2. The saved object cannot share a name with a column in x$table_body. The reason for this is that in tbl_merge() the columns are renamed, and the renaming process cannot disambiguate the variable column from an external object named variable in the following expression rows = .data$variable = .env$variable.

cols_merge_pattern argument

There are planned updates to the implementation of column merging. Currently, this function replaces the numeric column with a formatted character column following cols_merge_pattern=. Once gt::cols_merge() gains the rows= argument the implementation will be updated to use it, which will keep numeric columns numeric. For the vast majority of users, the planned change will be go unnoticed.

See Also

modify_table_body()

Other Advanced modifiers: modify_column_hide(), modify_fmt_fun(), modify_table_body()


gtsummary

Presentation-Ready Data Summary and Analytic Result Tables

v1.4.0
MIT + file LICENSE
Authors
Daniel D. Sjoberg [aut, cre] (<https://orcid.org/0000-0003-0862-2018>), Michael Curry [aut] (<https://orcid.org/0000-0002-0261-4044>), Margie Hannum [aut] (<https://orcid.org/0000-0002-2953-0449>), Joseph Larmarange [aut] (<https://orcid.org/0000-0001-7097-700X>), Karissa Whiting [aut] (<https://orcid.org/0000-0002-4683-1868>), Emily C. Zabor [aut] (<https://orcid.org/0000-0002-1402-4498>), Esther Drill [ctb] (<https://orcid.org/0000-0002-3315-4538>), Jessica Flynn [ctb] (<https://orcid.org/0000-0001-8310-6684>), Jessica Lavery [ctb] (<https://orcid.org/0000-0002-2746-5647>), Stephanie Lobaugh [ctb], Gustavo Zapata Wainberg [ctb] (<https://orcid.org/0000-0002-2524-3637>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.