| Title: | Render Tables in Text for the Terminal |
|---|---|
| Description: | Render tables in text format in the terminal using ANSI strings thanks to the 'cli' and 'crayon' packages. |
| Authors: | Karl Forner [aut, cre, cph] |
| Maintainer: | Karl Forner <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-05-19 08:01:51 UTC |
| Source: | https://github.com/kforner/clitable |
Render tables in text format in the terminal using ANSI strings thanks to the 'cli' and 'crayon' packages.
can display any ansi string (without end of lines) content
multiple table border styles: single, double, single-double, double-single, classic
can display heatmaps
can highlight rows
can display NAs with custom style
few dependencies: only crayon and cli
Maintainer: Karl Forner [email protected] [copyright holder]
Useful links:
generates a text table
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, ... )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, ... )
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 |
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 |
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 |
NA_style |
the (crayon) style to use to highlight the NA values (cf |
... |
Arguments passed on to
|
the lines of the text table as an ansi_string vector
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")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")
a function to demo the clitable package
demo()demo()
nothing
demo()demo()
scales a numeric vector
scale_numeric(x, xmin = min(x, na.rm = TRUE), xmax = max(x, na.rm = TRUE))scale_numeric(x, xmin = min(x, na.rm = TRUE), xmax = max(x, na.rm = TRUE))
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 |
a numeric vector of the same length as x, with all values between 0 and 1, except for NAs which are unchanged
x <- c(0.1, 100, -2.5, 20, 78.2, NA) scaled <- scale_numeric(x) all(is.na(scaled) | (scaled >= 0 & scaled <= 1))x <- c(0.1, 100, -2.5, 20, 78.2, NA) scaled <- scale_numeric(x) all(is.na(scaled) | (scaled >= 0 & scaled <= 1))