apa_format_columns() formats the columns of a data frame of results and
renames their headers in APA style, using a set of column_formats().
apa_flextable() calls it when auto_format_columns = TRUE.
Usage
apa_format_columns(
data,
column_formats = NULL,
no_format_columns = NULL,
rename_headers = TRUE,
latex_headers = FALSE,
format_separated_headers = TRUE,
sep = "_",
accuracy = NULL
)Arguments
- data
data set (data.frame or tibble)
- column_formats
column_formatsobject. If NULL, the current default formatter set withapa7_defaults()will be used.- no_format_columns
Column name or tidyselect function. selected columns are not formatted
- rename_headers
if
TRUE, rename headers with markdown or latex- latex_headers
if
TRUE, rename headers with latex instead of markdown- format_separated_headers
if
TRUE, format headers with separated names. For example, if the formatter formats columnR2as*R*^2^, thenModel 1_R2becomesModel 1_*R*^2^)- sep
separator for separated headers (default is "_")
- accuracy
numeric (default: NULL, uses the current default accuracy set with
apa7_defaults()). If not NULL, sets the accuracy for the formatter.
Details
Each column is matched by name to a column_format() in column_formats
(e.g., p, SE, beta, or R2). The values of a matched column are
formatted by the format's formatter, and its name is replaced by the
format's markdown header (e.g., beta becomes *β*), or by its LaTeX
header if latex_headers = TRUE. Columns without a format, and columns
named in no_format_columns, are left as they are.
If format_separated_headers = TRUE (default), a column name with a
separator (sep, an underscore by default) is matched by its last part, so
Model 1_R2 is formatted like R2 and becomes Model 1_*R*^2^. In
apa_flextable(), the part before the separator becomes a column spanner.
Format names that contain an underscore themselves (e.g., R2_adjusted) are
matched whole.
A few columns are matched by a pattern or combined:
CI,CI_low, andCI_high(e.g., fromparameters::parameters()) become a single column of intervals, with a header such as "95% CI" that gives the confidence level stored inCI. Prefixed columns are combined the same way for each column spanner (e.g.,Model 1_CI,Model 1_CI_low, andModel 1_CI_highbecomeModel 1_95% CI). ACIcolumn without its bounds is left as it is.If there are
tanddf_errorcolumns, the degrees of freedom are moved into thetheader (e.g., t(28)), anddf_erroris dropped.A column named like
t(28)is formatted with thet_dfformat (and gets the header t(28)), and one named like90% CIwith theCI_percentformat.
To see the default formats, run column_formats()@get_tibble. The article
Building Tables by Hand
shows how to change them.
Examples
lm(mpg ~ cyl + wt, data = mtcars) |>
parameters::parameters() |>
apa_format_columns() |>
apa_flextable()
Variable
B
SE
95% CI
t(29)
p
Constant
39.69
1.71
[36.18, 43.19]
23.14
<.001
Cyl
−1.51
0.41
[−2.36, −0.66]
−3.64
.001
Wt
−3.19
0.76
[−4.74, −1.64]
−4.22
<.001