Automating the generation of preformated text in Rmarkdown using R
I'm creating a document in which I repeat the same formatting multiple times. So I want to automate the process using the for loop in R. Here's a simple example. Assume, I have an R code that computes some information for all cut values in ggplot2::diamonds dataset, which I want then to print in my document in five separate sections (one section per cut): library(knitr); library(data.table) dt <- data.table(ggplot2::diamonds) for (cutX in unique(dt$cut)) { dtCutX <- dt[cut==cutX, lapply(.SD,mean), .SDcols=5:7] #### START of the Rmd part that needs to be printed # Section: The Properties of Cut