我有一个.rmd
文件,在其中将以下名称为bl_convergence_acorr001.png
的图像下载并保存到我的工作目录后,我创建了一个包含该图像和表的列表。然后,我试图通过Rmarkdown
创建Word文档,但是我创建了打印有此列表的Word文档,而不是图像和表格。
---
title: "Untitled"
author: "makis"
date: "March 14, 2019"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r t3, echo=FALSE,warning=FALSE,message=FALSE}
library(officer)
library(magrittr)
library(flextable)
current_dir <- getwd()
my_doc <- read_docx()
current_dir <- getwd()
my_doc <- read_docx()
#####
#with baseline
#Baseline Autocorrelation Plots
bl_acorr_files=list.files(path = current_dir, pattern = c("^bl_convergence_acorr",".png"))
for( i in 1:(length(bl_acorr_files))){
my_doc <- my_doc %>%
slip_in_text(paste0("Figure 1 Baseline Autocorrelation Plots"), style = "strong", pos = "after") %>%
body_add_img(src = paste0("bl_convergence_acorr00",i,".png") ,height = 5.75, width = 10 ,style = "centered")
}
summary_stats <- iris
ft <- flextable(data = summary_stats) %>%
theme_booktabs() %>%
autofit()
my_doc <- my_doc %>%
slip_in_text(paste0("Table 2: Summary stats"), style = "strong", pos = "after") %>%
body_add_flextable(ft)
my_doc
```