User-facing helper that prints a visually aligned, spicy-styled ASCII table
created by functions such as freq() or cross_table().
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.
Arguments
- x
A
spicy_tableordata.frameto be printed.- title
Optional title displayed above the table. Defaults to the
"title"attribute ofxif present.- note
Optional note displayed below the table. Defaults to the
"note"attribute ofxif present.- padding
Character string controlling horizontal spacing between columns:
"compact"— minimal spacing"normal"— moderate spacing (default)"wide"— extra spacing (for wide displays)
- first_column_line
Logical; if
TRUE(default), adds a vertical separator after the first column.- 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 (default:
TRUEfor all).- lines_color
Character; color for table separators (default:
"darkgrey"). Only applied if the output supports ANSI colors (seecrayon::has_color()).- align_left_cols
Integer vector of column indices to left-align. If
NULL(default), alignment is auto-detected based onx:For
freqtables →c(1, 2)For
crosstables →1
- ...
Additional arguments passed to
build_ascii_table().
Details
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.
See also
build_ascii_table() for the underlying text rendering engine.
print.spicy_freq_table() for the specialized printing method used by freq().
Examples
# 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"
)
#> Frequency table: Example
#> Category │ Values Freq. Percent
#> ──────────┼────────────────────────
#> Valid │ Yes 12 57.1
#> │ No 8 38.1
#> Missing │ NA 1 4.8
#> ──────────┼────────────────────────
#> Total │ 21 100
#> ──────────┴────────────────────────
#> Class: data.frame
#> Data: demo
