papaja (version 0.1.0.9842)

apa_table: Prepare table for printing

Description

Formats matrices and data.frames to report them as tables according to APA guidelines (6th edition).

Usage

apa_table(x, ...)

# S3 method for apa_results_table apa_table(x, escape = FALSE, ...)

# S3 method for matrix apa_table(x, caption = NULL, note = NULL, stub_indents = NULL, added_stub_head = NULL, col_spanners = NULL, midrules = NULL, placement = "tbp", landscape = FALSE, font_size = NULL, escape = TRUE, ..., format.args = NULL)

# S3 method for list apa_table(x, caption = NULL, note = NULL, stub_indents = NULL, added_stub_head = NULL, col_spanners = NULL, midrules = NULL, placement = "tbp", landscape = FALSE, font_size = NULL, escape = TRUE, merge_method = "indent", ..., format.args = NULL)

# S3 method for data.frame apa_table(x, caption = NULL, note = NULL, stub_indents = NULL, added_stub_head = NULL, col_spanners = NULL, midrules = NULL, placement = "tbp", landscape = FALSE, font_size = NULL, escape = TRUE, ..., format.args = NULL)

Arguments

x

Object to print, can be matrix, data.frame, or list. See details.

...

Arguments passed on to knitr::kable

x

An R object, typically a matrix or data frame.

format

A character string. Possible values are latex, html, markdown, pandoc, and rst; this will be automatically determined if the function is called within knitr; it can also be set in the global option knitr.table.format. If format is a function, it must return a character string.

digits

Maximum number of digits for numeric columns, passed to round(). This can also be a vector of length ncol(x), to set the number of digits for individual columns.

row.names

Logical: whether to include row names. By default, row names are included if rownames(x) is neither NULL nor identical to 1:nrow(x).

col.names

A character vector of column names to be used in the table.

align

Column alignment: a character vector consisting of 'l' (left), 'c' (center) and/or 'r' (right). By default or if align = NULL, numeric columns are right-aligned, and other columns are left-aligned. If length(align) == 1L, the string will be expanded to a vector of individual letters, e.g. 'clc' becomes c('c', 'l', 'c'), unless the output format is LaTeX.

caption

The table caption.

format.args

A list of arguments to be passed to format() to format table values, e.g. list(big.mark = ',').

escape

Boolean; whether to escape special characters when producing HTML or LaTeX tables.

escape

Logical. If TRUE special LaTeX characters, such as % or _, in column names, row names, caption, note and table contents are escaped.

caption

Character. Caption to be printed above the table.

note

Character. Note to be printed below the table.

stub_indents

List. A named list of vectors that contain indeces of the rows to indent. The name of each list element containing the vector is used as title for indented sections.

added_stub_head

Character. Used as stub head (name of first column) if row.names = TRUE is passed to kable; ignored if row names are omitted from the table.

col_spanners

List. A named list of vectors of length 2 that contain the first and last column to span. The name of each list element containing the vector is used as grouping column name. Ignored in MS Word documents.

midrules

Numeric. Vector of line numbers in table (not counting column headings) that should be followed by a horizontal rule; ignored in MS Word documents.

placement

Character. Indicates whether table should be placed at the exact location (h), at the top (t), bottom (b), or on a separate page (p). Arguments can be combined to indicate order of preference (htb); ignored when longtable = TRUE, landscape = TRUE, and in MS Word documents.

landscape

Logical. If TRUE the table is printed in landscape format; ignored in MS Word documents.

font_size

Character. Font size to use for table contents (can be tiny, scriptsize, footnotesize, small, normalsize (default), large, Large, LARGE, huge, Huge). Ignored in MS Word documents.

format.args

List. A named list of arguments to be passed to printnum to format numeric values.

merge_method

Character. Determines how to merge tables if x is a list. Can be either indent or table_spanner.

Details

When using apa_table, the type of the output (LaTeX or MS Word) is determined automatically by the rendered document type. If no rendering is in progress the output default is LaTeX. The chunk option of the enveloping chunk has to be set to results = "asis" to ensure the table is rendered, otherwise the table-generating markup is printed.

If x is a list, all list elements are merged by columns into a single table with the first column giving the names of the list elements elements.

See Also

kable, printnum

Examples

Run this code
# NOT RUN {
my_table <- t(apply(cars, 2, function(x) # Create data
  round(c(Mean = mean(x), SD = sd(x), Min = min(x), Max = max(x)), 2)
))

apa_table(
  my_table
  , align = c("l", rep("r", 3))
  , caption = "A summary table of the cars dataset."
)

apa_table(
  cbind(my_table, my_table)
  , align = c("l", rep("r", 8))
  , caption = "A summary table of the cars dataset."
  , note = "This table was created using apa\\_table()"
  , added_stub_head = "Variables"
  , col_spanners = list(`Cars 1` = c(2, 5), `Cars 2` = c(6, 9))
)

apa_table(
  list(`Cars 1` = my_table, `Cars 2` = my_table)
  , caption = "A summary table of the cars dataset."
  , added_stub_head = "Variables"
)
# }

Run the code above in your browser using DataCamp Workspace