kableHighlightColumns: Highlight Columns in Kable

View source: R/kableHighlightColumns.R

kableHighlightColumnsR Documentation

Highlight Columns in Kable

Description

Basic highlighting of each cell in a table based on a binary condition. Note that this uses cell_spec, which is deprecated in favor of column_spec, but I haven't figured out how to achieve this is column_spec yet.

Usage

kableHighlightColumns(
  data_dt,
  cols_v,
  condition_v,
  bgColor_v = c("white", "red"),
  tColor_v = c("black", "white"),
  ...
)

Arguments

data_dt

data.table to color columns of

cols_v

vector of column names to highlight cells of

condition_v

character string of condition to determine cell color. See details

bgColor_v

vector of length two containing color values to color cell backgrounds with

tColor_v

vector of length two containing color values to color cell text with

Details

Condition will be fed into an ifelse statement and each column provided in cols_v will be checked against it. For example, condition_v = "> 5" will be evaluated such that background = ifelse(data_dt[[col_v[i]]] > 5, bgColor_v[1], bgColor_v[2]), where i is the index of the current column. (And the same for text color).

Value

Output a kable with "standard" formatting updated with highlighted cells as defined in arguments.


weshorton/wrh.rUtils documentation built on Oct. 28, 2024, 7:24 a.m.