I have a shiny app that exports parameters from model building to a Rmd file which is knit using rmarkdown::render. I'd like to show the user a short synopsis of what the app did by generating a report with code chunks that will echo some of what the app did. So if for instance, the user made a linear model with y and x. I'd like the HTML report knit from the Rmd to read something like.
"You made a model using x and y, it was executed this syntax:
yourModel <- lm(y~x)" where x and y are read from objects theXs and theYs. I can do that in the Rmd with something like
Your first model was looked like this:
`yourModel <- lm( `r theYs[1]` ~ `r theXs[1]`)`
I want to generate text like that in the Rmd file but loop through all the parameters that have been passed in the Rmd doc. Here is an example of the kind of Rmd doc I want to generate. In this case there are three separate code chunks I want printed in the final HTML doc and I've shown the first two by hard coding. How can I automate this for a varying number of rows in the params object?
---
title: "Untitled"
output: html_document
---
## Step through a data.frame of parameters by row
```{r}
params <- data.frame(id = 1:3, y=rep("Ozone",3),
x = c("Solar.R","Wind","Temp + Wind"))
```
Example of what I want printed to the HTML doc using the first row of `params`
```
id`r params$id[1]`Model <- lm(`r params$y[1]` ~ `r params$x[1]`, data = airquality)
```
Example of what I want printed to the HTML doc using the second row of `params`
```
id`r params$id[2]`Model <- lm(`r params$y[2]` ~ `r params$x[2]`, data = airquality)
```
And so on for all rows of `params` but the number of rows will differ.