我是Rmarkdown的新手,并尝试生成一个具有一些条件文本格式的表。除了颜色外,桌子就像我想要的那样。例如,它显示\ textcolor {red} {50}而不是红色的50。知道我做错了吗?
在我的R脚本中:
table2 <- data %>% filter(student == 1) %>%
dplyr::mutate(grade = cell_spec(grade, "latex", color = ifelse(grade > 75, "blue", "red"))
在我的Rmarkdown文件中:
```{r, results = "asis"}
kable(table2, format = "latex")
```
答案 0 :(得分:2)
您的问题不可重现,但问题似乎是您在escape = FALSE
的调用中未包含kable
:
library(dplyr)
library(kableExtra)
data <- data.frame(student = rep(1:5, 2), grade = sample(100, 10))
table2 <- data %>% filter(student == 1) %>%
dplyr::mutate(grade = cell_spec(grade, "latex",
color = ifelse(grade > 75, "blue", "red")))
kable(table2, format = "latex", escape = FALSE)