I analyze survey results regularly and like to use Rmarkdown so I can make nice HTML output of the results.
The surveys can be many questions (like 40), so creating 40 code chunks, with highly repetitive code and headers, can be annoying. And I can easily do this with a loop in R, I think. However, I'm just stuck on how to combine these 2 processes!
This was close -- how to create a loop that includes both a code chunk and text with knitr in R
But in the end, it was just a loop, and not very flexible. So, I couldn't add a figure to question 22 (or whatever).
### Question 1
#### `r key$Question_Text[key$Question=="Q1"][1]`
```{r chunk1}
quest <- "Q1"
# code for question 1
```
### Question 2
#### `r key$Question_Text[key$Question=="Q2"][1]`
```{r chunk2}
quest <- "Q2"
# Identical code for question 2
```
....and so on....
### Question 35
#### `r key$Question_Text[key$Question=="Q35"][1]`
```{r chunk35}
quest <- "Q35"
# Identical code for question 35
```
Because sometimes, a question has a special type of figure or tweak, I want the output to be something I can paste into RMD and make all the changes there. I just want to skip ahead as much as possible... by making all the boring, identical steps, fully automated.