Skip to contents

generates a text table

Usage

cli_table(
  mat,
  header = TRUE,
  header_style = NULL,
  border_style = "single",
  heatmap_columns = NULL,
  heatmap_colorspace = c("green", "red"),
  hilite_rows = NULL,
  hilite_style = "bgRed",
  NA_style = NULL,
  ...
)

Arguments

mat

the table content to print, can be a data.frame or a matrix

header

whether to use the row names as table headers

header_style

the (crayon) style to use to print the headers (cf crayon::style()

border_style

the style to use for the table borders, one of single, double, single-double, double-single, classic

heatmap_columns

the columns that should be displayed as heatmaps, as a vector of column indices, names or logicals

heatmap_colorspace

the colorspace to use for the heatmaps, to be passed to grDevices::colorRamp()

hilite_rows

the rows to highlight, as a vector of column indices, names or logicals

hilite_style

the (crayon) style to use to highlight the rows (cf crayon::style()

NA_style

the (crayon) style to use to highlight the NA values (cf crayon::style()

...

Arguments passed on to scale_numeric

x

the numeric vector to scale

xmin

the minimum value used for the scaling. all all x < xmin are set to 0

xmax

the maximum value used for the scaling. all x > xmax set to 1

Value

the lines of the text table as an ansi_string vector

Examples

  df <- head(datasets::penguins, 20)
  ct <- cli_table(df, header_style = "bold",
    NA_style = "strikethrough",
    heatmap_columns = list("flipper_len"), xmin = 180, xmax = 200,
    hilite_rows = !is.na(df$sex) & df$sex == "female" & df$bill_dep >= 19, 
    hilite_style = "bgGreen"
  )
  cat(ct, sep = "\n")
#> ┌───────┬─────────┬────────┬────────┬───────────┬─────────┬──────┬────┐
#> │species│ island  │bill_len│bill_dep│flipper_len│body_mass│ sex  │year│
#> ├───────┼─────────┼────────┼────────┼───────────┼─────────┼──────┼────┤
#> │ Adelie│Torgersen│ 39.1   │ 18.7   │ 181       │ 3750    │ male │2007│
#> │ Adelie│Torgersen│ 39.5   │ 17.4   │ 186       │ 3800    │female│2007│
#> │ Adelie│Torgersen│ 40.3   │ 18.0   │ 195       │ 3250    │female│2007│
#> │ Adelie│Torgersen│ NANANANANA   │2007│
#> │ Adelie│Torgersen│ 36.7   │ 19.3   │ 193       │ 3450    │female│2007│
#> │ Adelie│Torgersen│ 39.3   │ 20.6   │ 190       │ 3650    │ male │2007│
#> │ Adelie│Torgersen│ 38.9   │ 17.8   │ 181       │ 3625    │female│2007│
#> │ Adelie│Torgersen│ 39.2   │ 19.6   │ 195       │ 4675    │ male │2007│
#> │ Adelie│Torgersen│ 34.1   │ 18.1   │ 193       │ 3475    │ NA   │2007│
#> │ Adelie│Torgersen│ 42.0   │ 20.2   │ 190       │ 4250    │ NA   │2007│
#> │ Adelie│Torgersen│ 37.8   │ 17.1   │ 186       │ 3300    │ NA   │2007│
#> │ Adelie│Torgersen│ 37.8   │ 17.3   │ 180       │ 3700    │ NA   │2007│
#> │ Adelie│Torgersen│ 41.1   │ 17.6   │ 182       │ 3200    │female│2007│
#> │ Adelie│Torgersen│ 38.6   │ 21.2   │ 191       │ 3800    │ male │2007│
#> │ Adelie│Torgersen│ 34.6   │ 21.1   │ 198       │ 4400    │ male │2007│
#> │ Adelie│Torgersen│ 36.6   │ 17.8   │ 185       │ 3700    │female│2007│
#> │ Adelie│Torgersen│ 38.7   │ 19.0   │ 195       │ 3450    │female│2007│
#> │ Adelie│Torgersen│ 42.5   │ 20.7   │ 197       │ 4500    │ male │2007│
#> │ Adelie│Torgersen│ 34.4   │ 18.4   │ 184       │ 3325    │female│2007│
#> │ Adelie│Torgersen│ 46.0   │ 21.5   │ 194       │ 4200    │ male │2007│
#> └───────┴─────────┴────────┴────────┴───────────┴─────────┴──────┴────┘