| spicy_print_table | R Documentation |
User-facing helper that prints a visually aligned, spicy-styled ASCII table
created by functions such as freq() or cross_tab().
It automatically adjusts column alignment, spacing, and separators for
improved readability in console outputs.
This function wraps the internal renderer build_ascii_table(), adding
optional titles, notes, and automatic alignment rules depending on the type
of table.
spicy_print_table(
x,
title = attr(x, "title"),
note = attr(x, "note"),
padding = c("compact", "normal", "wide"),
first_column_line = TRUE,
row_total_line = TRUE,
column_total_line = TRUE,
bottom_line = FALSE,
lines_color = "darkgrey",
align_left_cols = NULL,
...
)
x |
A |
title |
Optional title displayed above the table. Defaults to the
|
note |
Optional note displayed below the table. Defaults to the |
padding |
Character string controlling horizontal spacing between columns:
|
first_column_line |
Logical. If |
row_total_line, column_total_line, bottom_line |
Logical flags controlling
the presence of horizontal lines before total rows/columns or at the bottom
of the table.
Both |
lines_color |
Character. Color for table separators. Defaults to |
align_left_cols |
Integer vector of column indices to left-align.
If
|
... |
Additional arguments passed to |
spicy_print_table() detects whether the table represents frequencies
(freq-style) or cross-tabulations (cross-style) and adjusts formatting
accordingly:
For frequency tables, the first two columns (Category and Values) are left-aligned.
For cross tables, only the first column (row variable) is left-aligned.
The function supports Unicode line-drawing characters and colored separators using the crayon package, with graceful fallback to monochrome output when color is not supported.
Invisibly returns x, after printing the formatted ASCII table to the console.
build_ascii_table() for the underlying text rendering engine.
print.spicy_freq_table() for the specialized printing method used by freq().
# Simple demonstration
df <- data.frame(
Category = c("Valid", "", "Missing", "Total"),
Values = c("Yes", "No", "NA", ""),
Freq. = c(12, 8, 1, 21),
Percent = c(57.1, 38.1, 4.8, 100.0)
)
spicy_print_table(df,
title = "Frequency table: Example",
note = "Class: data.frame\nData: demo"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.