Reputation: 524
In short: how can I print a html-header inside a chunk in rmarkdown (use a variable to create a header inside a code-chunk)?
In long:
Let's say I have a number of variables in my dataset (names also stored in the vector 'Vars'), and each group of 3 variables belongs to the same subject.
I can make a loop to plot all the variables, but I want the subject in a title. Something like:
Plot Var1
Plot Var2
Plot Var3
Plot Var 4
Plot Var 5
...
Following pseudo-code hopefully explains what I want to do:
```{r}
for (i in Vars)
if(i%%3 == 1){
print(## Subject[ceiling(i/3)])}
plot(i)
```
Upvotes: 5
Views: 1848
Reputation: 10215
```{r, results="asis", echo = FALSE}
i = 1
cat("## Subject", i, "\n")
plot(i)
i = 2
cat("\n\n## Subject", i, "\n")
plot(i)
```
Upvotes: 8