50
20
kable
kable
Create tables in LaTeX, HTML, Markdown and reStructuredText
Description
This is a very simple table generator. It is simple by design. It is not intended to replace any other
Rpackages for making tables.
Usage
kable(x, format, digits = getOption("digits"), row.names = NA, col.names = NA, align,
caption = NULL, format.args = list(), escape = TRUE, ...)
Arguments
x
an R object (typically a matrix or data frame)
format
acharacter string; possible values arelatex, html, markdown, pandoc, andrst;
this will beautomaticallydetermined if the function iscalledwithin knitr;itcan
also be set in the global option knitr.table.format; if format is a function,
it must return a character string
digits
the maximum number of digits for numeric columns (passed toround()); itcan
also be a vector of length ncol(x) to set the number of digits for individual
columns
row.names
alogical value indicating 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
acharacter vector of column names to be used in the table
align
the alignment of columns: a character vector consisting of l (left), c (cen-
ter) and/or r (right); by default, numeric columns are right-aligned, andother
columns are left-aligned; if align = NULL, the default alignment is used
caption
the table caption
format.args
alist of arguments tobe passedtoformat()toformattablevalues, e.g. list(big.mark = ,)
escape
escape special characters when producing HTML or LaTeX tables
...
other arguments (see examples)
Value
Acharacter vector of the table source code.
Note
The tables for format = markdown also work for Pandoc when the pipe_tables extension is
enabled (this is the default behavior for Pandoc >= 1.10).
When using kable() as a top-level expression, you do not need to explicitly print() it due to R’s
automatic implicit printing. When it is wrapped inside other expressions (such as afor loop), you
must explicitly print(kable(...)).
References
Seehttps://github.com/yihui/knitr-examples/blob/master/091-knitr-table.Rnw for some
examples in LaTeX, but they also apply to other document formats.