Learn R Programming

iotables (version 0.9.4)

create_knitr_table: Create an output-independent, formatted kable table

Description

Wrapper around knitr::kable() with sensible defaults for alignment, borders, and formatting, compatible with HTML and LaTeX output formats.

Usage

create_knitr_table(
  data_table,
  digits = NULL,
  caption = NA,
  col.names = NULL,
  col_width = NULL,
  width_unit = "cm",
  col_align = NULL,
  border_right_cols = NULL,
  bold_cols = NULL,
  bootstrap_options = c("striped", "hover", "condensed"),
  latex_options = NULL,
  output_format = NULL,
  keep_pdf = FALSE,
  latex_header_includes = c("\\usepackage[magyar]{babel}",
    "\\usepackage[utf8]{inputenc}")
)

Value

A knitr_kable object with styling applied.

Arguments

data_table

A data.frame, tibble, named matrix, or knitr_kable object.

digits

Number of digits to display for numeric variables. Defaults to getOption("digits").

caption

Optional table caption. Defaults to NA (no caption).

col.names

Column names for the table. If NULL, uses names(data_table).

col_width

Numeric vector of column widths. If NULL, defaults to 2 for the first column and equal share for the rest.

width_unit

Character. Unit for column widths (default "cm").

col_align

Column alignment. Defaults to "l" for the first column, "c" for others.

border_right_cols

Logical vector for right-hand column borders. Defaults to TRUE for the first column, FALSE otherwise.

bold_cols

Logical vector. If TRUE, makes the column bold. Defaults to all FALSE.

bootstrap_options

Passed to kableExtra::kable_styling() for HTML output. Defaults to c("striped", "hover", "condensed").

latex_options

Passed to kableExtra::kable_styling() for LaTeX output. Defaults to c("scale_down", "striped").

output_format

Character: "html", "latex", or "image". If NULL, auto-detects from knitr options.

keep_pdf

Logical. Only relevant for output_format = "image". Defaults to FALSE.

latex_header_includes

Character vector of LaTeX headers to include. Defaults to c("\\usepackage[magyar]{babel}", "\\usepackage[utf8]{inputenc}").