r语言 - rmarkdown word文档中的HTML格式表格



我必须比较数据中的一些值并显示每周趋势。我想显示一个值是否比上周增加了。我已经创建了一个降价报告来做到这一点。下面显示了一个示例代码,它在output: html_document时工作正常,但在使用时输出会搞砸output: word_document

---
title: "trials"
author: "Foo Bar"
date: "15 December 2016"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r cars, echo=FALSE, cache=FALSE, message=FALSE}
library(dplyr, quietly = TRUE)
library(abind, quietly = TRUE)
virginica <- iris %>% filter(Species == "virginica") %>% head() %>% select(-Species)
setosa <- iris %>% filter(Species == "setosa") %>% head() %>% select(-Species)
diff_mat <- virginica - setosa

diff_mat[diff_mat<0] <- '<font color="green">&dArr; </font>'
diff_mat[diff_mat>0] <- '<font color="red">&uArr; </font>'
diff_mat[diff_mat == 0] <- '<font color="blue">&hArr; </font>'
datArray <- abind::abind(virginica, diff_mat, along=3)
fin_dat <- apply(datArray,1:2, function(x)paste(x[1],x[2], sep = " "))
knitr::kable(fin_dat, format = "html",
escape = FALSE, table.attr = "border=1",
caption = "Changes across species")
```

如何设置类似于 html 版本的文档的 word 版本的格式?

may render("my_document.rmd", "Grmd::d ocx_document").这适用于 html 表格,但与使用样式模板不兼容。它确实保留了表结构,包括列扳手。

最新更新