Rmarkdown Word文档中的HTML格式表 [英] HTML formatted tables in rmarkdown word document
问题描述
我必须比较数据中的某些值并显示每周趋势.我想显示值是否比上周有所增加.我已经创建了一个rmarkdown报告来做到这一点.下面显示了一个示例代码,该代码在output: html_document
时非常有效,但在使用output: word_document
I have to compare some values in data and display weekly trends. I want to show if a value has increased from last week. I have created an rmarkdown report to do it. An example code is shown below, which works perfectly when output: html_document
but output is messed up when using 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">⇓ </font>'
diff_mat[diff_mat>0] <- '<font color="red">⇑ </font>'
diff_mat[diff_mat == 0] <- '<font color="blue">⇔ </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版本相似的文档单词版本?
How can I format the word version of the document similar to the html version?
推荐答案
也许render("my_document.rmd","Grmd :: docx_document").这对于html表效果不错,但是与使用样式模板不兼容.它确实保留了表格结构,包括列扳手.
Perhaps render("my_document.rmd", "Grmd::docx_document"). This works decently for html tables but is not compatiple with using a styles template. It does keep the table structure, including column spanners.
这篇关于Rmarkdown Word文档中的HTML格式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!