column_format: Column format class

column_formatR Documentation

Column format class

Description

This class is used to define the format of columns in tables, including the name, header, latex representation, a formatter function, and what the header abbreviates.

Usage

column_format(
  name = character(0),
  header = character(0),
  latex = character(0),
  formatter = function() NULL,
  abbreviation = character(0)
)

Arguments

name

name of column

header

markdown representation of header name

latex

latex representation of header name

formatter

function that formats the column values. It should take a vector of values and return a character vector of formatted values.

abbreviation

what the header stands for, used by apa_note() to define the abbreviations in a table's note (e.g., "standardized coefficient" defines the ⁠β⁠ header as "β = standardized coefficient"). The term defined is the header, unless the string is named (e.g., c(CI = "confidence interval") defines "CI" for a header such as "95% CI"). Leave empty (the default) for symbols that need no definition, such as M, SD, t, and p.

Details

A column_format is an S7 object. Its properties are read and changed with @ (e.g., R2@header, or R2@formatter <- my_function). Formats are collected in a column_formats() object, in which each format is read, added, or replaced with $ (e.g., column_formats()$p). The table functions use a format for every column with the same name as the format.

Value

column_format object

Examples

R2 <- column_format(
         "R2",
         header = "*R*^2^",
         latex = "$R^2$",
         formatter = \(x, accuracy = .01, ...) {
                       align_chr(x,
                                 accuracy = accuracy,
                                 trim_leading_zeros = TRUE,
                                 ...)
                       })
R2
R2@header
R2@formatter(c(.123, .45))

# Define an abbreviation in table notes
SS <- column_formats()$Sum_Squares
SS@abbreviation <- "sum of squares"

apa7 documentation built on Dec. 1, 2026, 5:06 p.m.