kableExtra v0.9.0

0

Monthly downloads

0th

Percentile

Construct Complex Table with 'kable' and Pipe Syntax

Build complex HTML or 'LaTeX' tables using 'kable()' from 'knitr' and the piping syntax from 'magrittr'. Function 'kable()' is a light weight table generator coming from 'knitr'. This package simplifies the way to manipulate the HTML or 'LaTeX' codes generated by 'kable()' and allows users to construct complex tables and customize styles using a readable syntax.

Readme

kableExtra logo

CRAN_version CRAN_download CRAN_download_total


When we are talking about table generators in R, knitr's kable() function is usually a popular choice because of its ultimate simplicity. Unlike those powerful table rendering engines such as xtable, the philosophy behind knitr::kable() is to make it easy for programmers to use. Just as it claimed in its function description,

This is a very simple table generator. It is simple by design. It is not intended to replace any other R packages for making tables. - Yihui

However, the ultimate simplicity of kable() also brought troubles to some of us, especially for new R users, who may not have a lot of experience on generating tables in R. It is not rare to see people including experienced users asking questions like how to center/left-align a table on Stack Overflow. Also, for me personally, I found myself repeatedly parsing CSS into kable() for some very simple features like striped lines. For LaTeX, it's even worse since I'm almost Stack Overflow dependent for LaTeX... That's why this package kableExtra was created.

I hope with kableExtra, you can

  • Use default base kable() (Or a good alternative for markdown tables is pander::pander()) for all simple tables
  • Use kable() with kableExtra to generate 90 % of complex/advanced/self-customized/beautiful tables in either HTML or LaTeX
  • Only have to mess with raw HTML/LaTeX in the last 10% cases where kableExtra cannot solve the problem

This package can load required LaTeX package automatically in vanilla rmarkdown. For customized rmarkdown templates, it is recommended to load related LaTeX packages manually.


Features

Pipable syntax

kableExtra is NOT a table generating package. It is a package that can "add features" to a kable() output using a syntax that every useR loves - the pipes %>%. We see similar approaches to deal with plots in packages like ggvis and plotly. There is no reason why we cannot use it with tables.

Unified functions for both HTML and PDF

Most functionalities in kableExtra can work in both HTML and PDF. In fact, as long as you specifies format in kable() (which can be set globally through option knitr.table.format), functions in this package will pick the right way to manipulate the table be themselves. As a result, if users want to left align the table, kable(...) %>% kable_styling(position = "left") will work in both HTML and PDF.

Install

install.packages("kableExtra")

# For dev version
devtools::install_github("haozhu233/kableExtra")

Basic Usage

library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:4]

# HTML table
kable(dt, format = "html", caption = "Demo Table") %>%
  kable_styling(bootstrap_options = "striped",
                full_width = F) %>%
  add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>%
  add_footnote(c("table footnote"))

# LaTeX Table
kable(dt, format = "latex", booktabs = T, caption = "Demo Table") %>%
  kable_styling(latex_options = c("striped", "hold_position"),
                full_width = F) %>%
  add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>%
  add_footnote(c("table footnote"))

Results

More Information

For more information, please check the package vignette.

Acknowledgement

I would like to thank colleagues at Hebrew SeniorLife Institute for Aging Research and the Boston Pepper Center for their input. I also would like to appreciate the mentorship from Tom Travison (@tgt75) and all the efforts from the open source community, which help this package keep getting better.

Functions in kableExtra

Name Description
spec_color Generate viridis Color code for continuous values
spec_angle Generate rotation angle for continuous values
save_kable Save kable to files
spec_tooltip Setup bootstrap tooltip
usepackage_latex Load a LaTeX package
spec_font_size Generate common font size for continuous values
scroll_box Put a HTML table into a scrollable box
spec_popover Setup bootstrap popover
kable_styling HTML table attributes
row_spec Specify the look of the selected row
rmd_format Rmarkdown Format
add_header_above Add a header row on top of current header
add_footnote Add footnote
auto_index Automatically figuring out the group_row index
magic_mirror Magic mirror that returns kable's attributes
kable_as_image Convert a LaTeX table to an image and place it in a rmarkdown document
add_indent Add indentations to row headers
reexports Objects exported from other packages
footnote_marker_number Footnote marker
group_rows Put a few rows of a table into one category
kableExtra-package kableExtra
column_spec Specify the look of the selected column
footnote Add footnote (new)
kableExtra_latex_packages LaTeX Packages
html_dependency_kePrint HTML dependency for js script to enable bootstrap tooltip and popup message
cell_spec Specify Cell/Text format
collapse_rows Collapse repeated rows to multirow cell
html_dependency_bsTable HTML dependency for Twitter bootstrap (table only)
landscape Print the table on an isolated landscape page in PDF
linebreak Make linebreak in LaTeX Table cells
No Results!

Vignettes of kableExtra

Name
awesome_table_in_html.Rmd
awesome_table_in_pdf.Rmd
best_practice_for_newline_in_latex_table.Rmd
kableExtra_sm.png
legacy_features.Rmd
use_kableExtra_with_formattable.Rmd
use_kable_in_shiny.Rmd
No Results!

Last month downloads

Details

Type Package
License MIT + file LICENSE
LazyData TRUE
URL http://haozhu233.github.io/kableExtra/, https://github.com/haozhu233/kableExtra
BugReports https://github.com/haozhu233/kableExtra/issues
VignetteBuilder knitr
Encoding UTF-8
RoxygenNote 6.0.1
NeedsCompilation no
Packaged 2018-05-21 05:00:29 UTC; haozhu
Repository CRAN
Date/Publication 2018-05-21 05:22:54 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/kableExtra)](http://www.rdocumentation.org/packages/kableExtra)