当Rmarkdown编织到Word时,flextable :: save_as_image()包括图像的路径

时间:2020-06-17 19:54:39

标签: r flextable

当我将Rmarkdown编织到Word并包括一个使用flextable::save_as_image()保存为图像的表格时,该函数似乎还将路径粘贴到表格上方的图像中。如何防止该路径包含在Word文档中? 这是MWE:

---
title: "MWE"
output: word_document
---

```{r include=TRUE, message=FALSE, warning=FALSE, echo=FALSE, results='asis'}
library(flextable, quietly = TRUE)
library(webshot, quietly = TRUE)
ft <- flextable( head( mtcars ) )
ft <- autofit(ft)
save_as_image(x = ft, path = "myimage.png")
knitr::include_graphics("myimage.png")
```

这是我得到的输出:

enter image description here

1 个答案:

答案 0 :(得分:2)

save_as_image返回保存图像的文件名。您可以使用invisible()隐藏它。

invisible(save_as_image(x = ft, path = "myimage.png"))