我在 RStudio 中的 kableExtra 输出有一些问题。一旦我点击“编织”按钮,我正在尝试在 R 降价文件中创建一个格式化表格。
代码是:
kable(temp_table, "html") %>%
add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)) %>%
kable_styling(bootstrap_options = c("striped", "condensed", "hover", "responsive"), font_size = 11, full_width = FALSE, position = "left") %>%
column_spec(1, bold = T)
它应该创建一个带有我添加的标题行的简单表。但这不仅没有显示,而且变量行名也没有显示。表格前面是一堆看起来没有渲染的 HTML 代码。
一些版本历史:kableExtra - 0.6.1
knitr - 1.17
rmarkdown - 1.7
R - 3.3.3
RStudio - 1.1.258
对此有任何帮助将不胜感激!
---- 更新 ----
下面是一个简单的可重现的例子,它给了我同样的输出。
---
title: "Iris Example"
output_file: "iris2.html"
---
## Iris Data
``` {r iris, echo = FALSE, warning = FALSE}
library(data.table)
library(knitr)
library(kableExtra)
iris <- data.table(iris)
iris <- iris[, .(
sep_len = mean(Sepal.Length)
, sep_wid = mean(Sepal.Width)
, pet_len = mean(Petal.Length)
, pet_wid = mean(Petal.Width)
), by = .(Species)]
kable(iris, "html") %>%
add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2)) %>%
kable_styling(bootstrap_options = c("striped", "condensed", "hover", "responsive"), font_size = 10, full_width = FALSE, position = "left") %>%
column_spec(1, bold = T)
```