我有一个markdown文档,并希望基于一个变量从中生成多个报告。此处是一个示例(this的更新版本):
脚本文件:
library(knitr)
library(markdown)
library(rmarkdown)
library(glue)
library(tidyverse)
iris_rmd <- iris %>% distinct(Species) %>% pull
for (i in iris_rmd){
selected_iris <- iris_rmd[i]
render(input = "test_iris.Rmd", #the notebook file
output_file = glue("{i}_profile_{Sys.Date()}.html"),
output_dir = 'test_profiles')
}
笔记本文件:
---
output:
html_document:
self_contained: no
---
```{r, include = FALSE}
#DON'T KNIT
#RUN THE SCRIPT INSTEAD!!!
```
```{r, include = FALSE}
library(tidyverse)
library(glue)
```
```{r, include = FALSE}
# add variables
selected_iris <- i
data <- iris %>%
filter(Species == selected_iris)
```
```{r}
ggplot(data, aes(Sepal.Length, Sepal.Width)) +
geom_point() + labs(title = glue("{selected_iris}"))
```
我必须将YAML标头中的设置更改为self_contained: no
,如下所述:pandoc document conversion failed with error 67,但这会将图像放在单独的文件夹中。
但是,我想将图像包括在html文件中(将它们嵌入,就像在普通笔记本中一样)。我也尝试过同样的错误:R-markdown self_contained
有没有解决的办法?
版本详细信息:
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.2
year 2018
month 12
day 20
svn rev 75870
language R
version.string R version 3.5.2 (2018-12-20)
nickname Eggshell Igloo
还有
Rstudio 1.1.436
rmarkdown 1.12
rmarkdown::pandoc_version() ‘1.19.2.1’