SDS_table: Format data frames nicely for SDS book

sds_tableR Documentation

Format data frames nicely for SDS book

Description

Creates HTML or Latex markup with a footnote showing how many rows there are in total.

Usage

sds_table(
  data,
  show_n = 6L,
  nrows = nrow(data),
  row.names = FALSE,
  footnote = NULL,
  format = ifelse(knitr::is_latex_output(), "latex", "html"),
  caption = NULL,
  align = NULL,
  in_margin = knitr::opts_current$get("in_margin"),
  label = knitr::opts_current$get("label"),
  ...
)

Arguments

data

the data frame to be displayed

show_n

how many lines to display (default 6. Use Inf for all rows.)

nrows

an integer specifying how many rows the from the data frame should be displayed in the footnote. Set to Inf to suppress footnote.

row.names

whether to show the rownames in the table (def: FALSE)

footnote

character string to be placed at the bottom of the table in place of the usual "... and so on for __ rows."

format

either "html" or "latex". Default will use knitr::is_latex_output() to decide.

caption

string to pass as a caption to the table

align

optional column alignment instructions passed to kable

in_margin

If TRUE, format table to go in margin for LaTeX Tufte-style layout. BUT UNFORTUNATELY, THIS WORKS ONLY IN INLINE MODE, while htmlformats DON'T work in inline mode.

label

reference label for bookdown, e.g. "my-table" to empower reference with tab:my-table". By default, grabbed from chunk name.

...

additional arguments to kableExtra::kable_styling(), e.g. "striped", "hover"

Details

sds_table() can access the knitr chunk label and the value of in_margin. Don't output the value directly from the chunk. Instead, assign the output of sds_table() to a variable and use an inline expression to insert that variable.

Examples

sds_table(mtcars, "striped", "hover")
sds_table(mtcars, show_n = 3, caption="Data about cars")

dtkaplan/SDSdata documentation built on June 28, 2022, 8:09 a.m.