Produce tables in loop

Another one for me before I forget, I seem to have terrible problems writing headings and tables in a loop in RMarkdown. Everything gets crushed together because the line returns don’t seem to work properly and either the table or the headings get mangled. Well here it is, the thing I just did that worked:


for(i in 1:2){

  cat("Heading ", i, "\n")
  
  cat("===========================")
  
  pandoc.table(iris)
}

That’s it! Don’t put any other weird “\n”s or [HTML line breaks which I now realise WordPress will interpret literally] in. You don’t need them!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.