Make nice APA tables easily through a wrapper
around the flextable
package with sensical defaults and
automatic formatting features.
nice_table(
data,
highlight = FALSE,
stars = TRUE,
italics,
col.format.p,
col.format.r,
col.format.ci,
format.custom,
col.format.custom,
width = NULL,
spacing = 2,
broom = NULL,
report = NULL,
short = FALSE,
title,
note,
separate.header
)
An APA-formatted table of class "flextable"
The data frame, to be converted to a flextable. The data frame cannot have duplicate column names.
Highlight rows with statistically significant results? Requires a column named "p" containing p-values. Can either accept logical (TRUE/FALSE) OR a numeric value for a custom critical p-value threshold (e.g., 0.10 or 0.001).
Logical. Whether to add asterisks for significant p values.
Which columns headers should be italic? Useful for column names that should be italic but that are not picked up automatically by the function. Select with numerical range, e.g., 1:3.
Applies p-value formatting to columns that cannot be named "p" (for example for a data frame full of p-values, also because it is not possible to have more than one column named "p"). Select with numerical range, e.g., 1:3.
Applies r-value formatting to columns that cannot be named "r" (for example for a data frame full of r-values, also because it is not possible to have more than one column named "r"). Select with numerical range, e.g., 1:3.
Applies 95% confidence interval formatting to selected columns (e.g., when reporting more than one interval).
Applies custom formatting to columns
selected via the col.format.custom
argument. This is useful
if one wants custom formatting other than for p- or r-values.
It can also be used to transform (e.g., multiply) certain values
or print a specific symbol along the values for instance.
Which columns to apply the custom function to. Select with numerical range, e.g., 1:3.
Width of the table, in percentage of the
total width, when exported e.g., to Word. For full width,
use width = 1
.
Spacing of the rows (1 = single space, 2 = double space)
If providing a tidy table produced with the
broom
package, which model type to use if one wants
automatic formatting (options are "t.test", "lm", "cor.test",
and "wilcox.test").
If providing an object produced with the
report
package, which model type to use if one wants
automatic formatting (options are "t.test", "lm", and "cor.test").
Logical. Whether to return an abbreviated
version of the tables made by the report
package.
Optional, to add a table header, if desired.
Optional, to add one or more table footnote (APA note), if desired.
Logical, whether to separate headers based on name delimiters (i.e., periods ".").
The resulting flextable
objects can be opened in
Word with print(table, preview ="docx")
, or saved to
Word with the flextable::save_as_docx()
function.