Skip to contents

Bolds the body cells of chosen rows, with an option to recolor their text and fill their background. Rows are chosen by index or by a filter expression; with neither, every row is bolded.

Usage

gt_bold_rows(
  gt_object,
  rows = NULL,
  text_color = "black",
  highlight_color = NULL,
  row = NULL,
  filter_statement = NULL
)

Arguments

gt_object

A gt table object to modify.

rows

The rows to bold. Either an expression evaluated against the table's data, such as mpg > 20, or a numeric vector of row indices. If NULL, every row is bolded. Defaults to NULL.

text_color

Character. The text color for the bolded rows. Defaults to "black".

highlight_color

Character. The background fill for the bolded rows. Set to NULL for no fill. Defaults to NULL.

row

Deprecated. Use rows.

filter_statement

Deprecated. Use rows, which takes the expression directly rather than as a string.

Value

Returns a modified gt table with the chosen rows bolded.

Details

rows is evaluated against the table's underlying data, so rows = mpg > 20 bolds the rows where that is TRUE; a numeric vector picks rows by index. The deprecated row is passed on to rows, and the deprecated filter_statement string, when given, takes precedence over rows. The styling is applied with a single gt::tab_style() over gt::cells_body(), so it covers every column of the chosen rows.

Examples

library(gt)

# bold every row
gt(head(mtcars)) %>% gt_bold_rows()
mpg cyl disp hp drat wt qsec vs am gear carb
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
# bold and fill the rows above 20 mpg gt(head(mtcars)) %>% gt_bold_rows(rows = mpg > 20, highlight_color = "#FFF3B0")
mpg cyl disp hp drat wt qsec vs am gear carb
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
18.1 6 225 105 2.76 3.460 20.22 1 0 3 1