How to set knitr::kable() global options in markdown for reuse

岁酱吖の 提交于 2019-11-27 06:20:52

问题


Is there an easy to use way to setup custom default kable() options, so that there is no need in rewriting them for each kable() call.

For example, my usual table styling uses following code:

library(kableExtra)
kable(mtcars, booktabs=TRUE, digits= 2) %>% kable_styling(latex_options =c("striped", "scale_down"))

I would like to set all kable() kable_styling options so that a call to kable(mtcars) with no arguments defaults to my usual table styling.


回答1:


Just write your own function to do that:

kable <- function(data) {
  knitr::kable(data, booktabs = TRUE, digits = 2) %>% 
    kable_styling(latex_options =c("striped", "scale_down"))
}

It might be less confusing to give it a new name instead of masking kable; that's up to you.



来源:https://stackoverflow.com/questions/54168558/how-to-set-knitrkable-global-options-in-markdown-for-reuse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!