rmarkdown word文档

时间:2016-12-15 04:06:39

标签: r render knitr r-markdown

我必须比较数据中的一些值并显示每周趋势。我想显示一个值是否比上周有所增加。我创建了一个rmarkdown报告来做到这一点。示例代码如下所示,在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")

```

如何格式化文档的word版本,类似于html版本?

1 个答案:

答案 0 :(得分:0)

也许渲染(&#34; my_document.rmd&#34;,&#34; Grmd :: docx_document&#34;)。这适用于html表,但与使用样式模板不兼容。它确实保留了表结构,包括列扳手。