I am creating a multi-section PDF document using R markdown, knitr, and pander. Though I have read previous posts [blog]: Programmatically insert text, headers and lists with R markdown "posts" on this topic, I am still encountering problems.
The function I'm using to insert headers is:
I can only provide a skeletal version of the code, which is actually several hundred lines long:
{r , echo=FALSE, include = TRUE, warning = FALSE, results = 'asis'}
prt.scale.heading <- function(scale, iter) {
txt <- "Analysis of "
# add blank lines as suggested in previous post
cat("\n\n")
hdr <- paste(txt,scale,"Iteration",iter)
# show header using the R markdown '#' symbol
cat('\n#',hdr,'\n')
}
do_analysis <- function(resp.data, scale, maxChanges = 1,
filename = NULL) {
iter <- 0
while (iter <= maxChanges) {
prt.scale.heading(scale, iter)
iter <- iter + 1
}
}
do_analysis(resp.data = temp, scale.name, maxChanges = 5)
}
When I run my code, instead of seeing formatted section headers, I see the heading in plain text preceded by '#'. Note that all of the text, plots and tables (pander) are placed in one large chunk, and I set the chunk option results = 'asis' (as suggested in a previous post).
Suggestions?