我刚开始学习函数中的ifelse语句。这是一个简单的例子:
library(knitr)
Tab <- iris
my_kable <- function(x, html = TRUE) {
if(html) { # any expression here in parentheses is evaluated before it's passed on to the if statement
kable(x, kable_input = "html")
} else {
kable(x, kable_input = "latex")
}
}
my_kable(Tab, html = FALSE)
问题在于R Markdown,我是否把&#34; html = FALSE&#34;或&#34; html = TRUE&#34;我得到相同的结果(HTML表)。我知道我错过了很简单的事情......
我的错!我试图找到一个在knitr中不存在的选项。这有效:
if(html) {
kable(x, format = "html")
} else {
kable(x, format = "latex")
}