In my dataset, I have 60 groups that I want to analyze in put into an HTML report using R Markdown. Because I want to apply the same analysis to each group, I am hoping that there is a way I can dynamically generate the code blocks/analysis.
Simply, I want to avoid replicating the block 60 times.
I came across this this question which uses children in knitr
. I have attempted to replicate this with the iris dataset. In my example below, all I wanted to do was generate three H4 titles, one for each species.
It's worth noting that I am not married to this approach, it just appears to be related to what I am looking to do.
Here are the files I used:
parent.RMD
file. This would be my "master" report.
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'))
}
```
And here is child.Rmd
.
#### Species = `r [i]`
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…