knitr kable文本颜色不渲染

时间:2018-05-17 16:15:37

标签: r-markdown knitr textcolor kable

我是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")
 ```

1 个答案:

答案 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)