如何在markdown中设置knitr :: kable()全局选项以进行重用 [英] How to set knitr::kable() global options in markdown for reuse
本文介绍了如何在markdown中设置knitr :: kable()全局选项以进行重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种易于使用的方法来设置自定义默认kable()
选项,因此无需为每个kable()
调用重写它们.
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"))
我想设置所有kable()
kable_styling
选项,以便不带任何参数的kable(mtcars)
调用默认为我惯用的表样式.
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.
推荐答案
只需编写您自己的函数即可:
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"))
}
给它起一个新名字而不是掩盖kable
可能会减少混乱;这取决于你.
It might be less confusing to give it a new name instead of masking kable
; that's up to you.
这篇关于如何在markdown中设置knitr :: kable()全局选项以进行重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文