В моем наборе данных у меня есть 60 групп, которые я хочу проанализировать, помещая в HTML-отчет, используя R Markdown. Поскольку я хочу применить один и тот же анализ к каждой группе, я надеюсь, что есть способ, которым я могу динамически генерировать кодовые блоки/анализ.
Просто я хочу избежать повторного копирования блока 60 раз.
Я столкнулся с этим этим вопросом, который использует детей в knitr
. Я попытался воспроизвести это с помощью набора диафрагмы. В моем примере ниже все, что я хотел сделать, это генерировать три титула H4, по одному для каждого вида.
Стоит отметить, что я не женат на этом подходе, это просто похоже на то, что я ищу.
Вот файлы, которые я использовал:
parent.RMD
. Это будет мой "главный" отчет.
Automate Chunks of Analysis in R Markdown
========================================================
```{r setup, echo=FALSE}
library(knitr)
```
```{r run-numeric-md, include=FALSE}
out = NULL
for (i in as.character(unique(iris$Species))) {
out = c(out, knit_child('child.Rmd'))
}
`` `
И вот child.Rmd
.
#### Species = `r [i]`