我希望在一个R Markdown文档中打印多个弹性表格。这并不是使用html输出时的挑战,但我需要Word输出。
使用html输出,下面的R Markdown代码(取自https://davidgohel.github.io/flextable/articles/offcran/examples.html#looping-in-r-mardown-documents)生成一个具有多个Flextable的文档:
---
output:
html_document: default
---
```{r}库(Htmltools)
库(可伸缩)
ft <- flextable(头部(虹膜))
tab_list <- list()
对于(1:3中的i){
tab_list[i] <- tagList(
tags$h6(paste0("iteration ", i)),htmltools_value(ft))
}
tagList(tab_list)
我无法使用Word文档输出获得等效的输出。在How to knit_print flextable with loop in a rmd file中提出的解决方案同样适用于html输出,但我未能使其在Word输出中正确呈现。
任何关于R Markdown Word文档输出的建议都会非常有帮助!
发布于 2019-10-01 03:31:32
您需要使用flextable::docx_value和块选项results='asis'
---
title: "Untitled"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flextable)
```
```{r results='asis'}
ft <- flextable(head(iris))
for(i in 1:3){
cat("<w:p/>")## add this to add an empty new paragraph between tables
flextable::docx_value(ft)
}
```https://stackoverflow.com/questions/58173966
复制相似问题