print.spicy_freq_table: Styled print method for 'freq()' tables (spicy engine)

View source: R/freq_print.R

print.spicy_freq_tableR Documentation

Styled print method for freq() tables (spicy engine)

Description

Internal print method used by freq() to display a styled, spicy-formatted frequency table in the console. It formats valid, missing, and total rows; handles cumulative and valid percentages; and appends a labeled footer including metadata such as variable label, class, dataset name, and weighting information.

Usage

## S3 method for class 'spicy_freq_table'
print(x, ...)

Arguments

x

A data.frame returned by freq() with attached attributes:

  • "digits": number of decimal digits to display

  • "data_name": name of the source dataset

  • "var_name": name of the variable

  • "var_label": variable label, if defined

  • "class_name": original class of the variable

  • "weighted", "rescaled", "weight_var": weighting metadata

...

Additional arguments (ignored, required for S3 method compatibility)

Details

This function is part of the spicy table rendering engine. It is automatically called when printing the result of freq() with styled = TRUE. The output uses spicy_print_table() internally to render a colorized ASCII table with consistent alignment and separators.

The printed table includes:

  • Valid and missing value sections (if applicable)

  • Optional cumulative and valid percentages

  • A final 'Total' row shown in the Category column

  • A footer summarizing metadata (variable label, data source, weights)

Value

Invisibly returns x after printing the formatted table.

Output structure

The printed table includes the following columns:

  • Category: Sections such as "Valid", "Missing", and "Total"

  • Values: Observed categories or levels

  • Freq.: Frequency count (weighted if applicable)

  • Percent: Percentage of total

  • Valid Percent: Percentage among valid values (optional)

  • Cum. Percent: Cumulative percentage (optional)

  • Cum. Valid Percent: Cumulative valid percentage (optional)

See Also

freq() for the main frequency table generator. spicy_print_table() for the generic ASCII table renderer.

Examples

# Example using labelled data
library(labelled)
x <- labelled(
  c(1, 2, 3, 1, 2, 3, 1, 2, NA),
  labels = c("Low" = 1, "Medium" = 2, "High" = 3)
)
var_label(x) <- "Satisfaction level"
# Capture result without printing, then print explicitly
df <- spicy::freq(x, styled = FALSE)
print(df) # dispatches to print.spicy_freq_table()


spicy documentation built on March 14, 2026, 5:06 p.m.