custom_kable: custom_kable: A customized format using for printing tables

View source: R/custom_kable.R

custom_kableR Documentation

custom_kable: A customized format using for printing tables

Description

This function uses knitr::kable() and kableExtra::kable_styling to build a customized table that, in my opinion, looks better than the default.

Usage

custom_kable(
  data,
  digits = 3,
  caption = NA,
  col.names = NA,
  row.names = NA,
  format = NULL,
  escape = TRUE,
  format.args = list()
)

Arguments

data

A data frame or tibble. Matrices usually work, except when they don't.

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.

caption

The table caption.

col.names

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

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).

format

A character string. Possible values are latex, html, pipe (Pandoc's pipe tables), simple (Pandoc's simple tables), rst, and jira. The value of this argument will be automatically determined if the function is called within a knitr document. The format value can also be set in the global option knitr.table.format. If format is a function, it must return a character string.

escape

Boolean; whether to escape special characters when producing HTML or LaTeX tables. When escape = FALSE, you have to make sure that special characters will not trigger syntax errors in LaTeX or HTML.

format.args

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

Details

Missing values (NA) in the table are displayed as NA by default. If you want to display them with other characters, you can set the option knitr.kable.NA, e.g. options(knitr.kable.NA = '') to hide NA values.

Value

A character vector of the table source code.

Note

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 a for loop), you must explicitly print(kable(...)).

References

See https://bookdown.org/yihui/rmarkdown-cookbook/kable.html for some examples about this function, including specific arguments according to the format selected.

See Also

See kable and kable_styling

Examples

custom_kable(mtcars, caption = "A kable of mtcars")

sbw78/sbwtools documentation built on May 20, 2024, 9 a.m.