results asis: create section header, and print R output, inside a for loop

I posted this on StackOverflow but have no replies yet, so I'm asking here too.

I have a for loop in R, inside of which I want to create R Markdown section headers and print output from R functions such as summary(lm(...)). If I use {r results='asis'} at the start of the code chunk, I can get the section headers to work but the R output won't display properly. If I don't use results='asis' then the R output displays but the section headers won't work. How can I get R-created section headers and R output is the same code chunk, all inside a for loop? There's a complete example R Markdown script and output over at the Stack Overflow post. Thanks!

I think your use case is a good one to use a template file to knit in a look and insert asis in the main doc
See this chapter of the book

Child document could also be of interest using knit_child

Result asis is explained here:

I hope this helps you with your task

1 Like

Thank you for your reply. I read about child documents (that you pointed to) and created a solution that I posted on Stack Overflow. Thanks again.

1 Like

Glad you found a solution !

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.