commit | 8a6c16434059049451aa454d3f23103e64983999 | [log] [tgz] |
---|---|---|
author | Hao Zhu <haozhu233@gmail.com> | Wed Mar 01 15:09:15 2017 -0500 |
committer | Hao Zhu <haozhu233@gmail.com> | Wed Mar 01 15:09:15 2017 -0500 |
tree | 21cb12c27ef5f0f362804ae48c67092cb3f07505 | |
parent | 7c8cc4884c4fb5c07a3c7d615e8f164af93991bc [diff] |
update layout of doc index
When we are talking about table generators in R, knitr::kable wins the favor of a lot of people by its ultimate simplicity. Unlike those powerful table rendering engine such as xtable, tables or even gridExtra, the philosophy behind 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()
brought troubles to some people, especially some new R users who may not have got exposed to other table making packages in R. It is not rare to see people including experienced user asking questions like how to center/left-align a table on Stack Overflow or twitter. These are the reasons why this package kableExtra
was created.
I hope with kableExtra
, you can
kable()
for all simple tableskable()
with kableExtra
to generate 90 % of complex/advanced/self-customized/beautiful tables in either HTML or LaTeXkableExtra
cannot solve the problemkableExtra
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.
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.
Some LaTeX features in kableExtra
, such as striped line, requires rmarkdown 1.4.0+, which is not yet on CRAN. It is highly recommended to install the dev version of rmarkdown before you try this package. If you only use this package for HTML table, it doesn't matter what version of rmarkdown you are using.
# install.packages("devtools") devtools::install_github("rstudio/rmarkdown") # For dev version devtools::install_github("haozhu233/kableExtra")
kableExtra
will be submitted to CRAN soon.
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"))
For more information, please check the package vignette.
add_header_above
and add_footnote
should be able to work in any conditions but if you are using kable_styling
in customed templates it can get a little tricky.kable_styling
assumes you to have bootstrap 3 style sheet loaded to have all features functioning.