svenhalvorson svenhalvorson - 4 days ago 5
R Question

format code chunks knitr

I'm into my first attempt at using knitr to produce some reports for teachers based on their standardized test scores. Because the number of exams tied to each teacher is different, I'm trying to use a loop within a code chunk to produce this portion of the reports. As a result, I'm finding it hard to format the text and make it readable. Any advice on how I can get some simple centering and/or bold to make the pages more readable. Here's a stripped down example:

\documentclass{article}

\begin{document}
\title{TEST RESULTS}
\maketitle


<<Categories, echo = FALSE, message = FALSE, results = "asis">>=
TestCode = c("math","art", "reading")
for(i in unique(TestCode)){
cat("\n\n\\pagebreak\n")
cat("Exam :",i,"\n\n","TEXTY TEXT TEXT")
}

@


\end{document}


The goal is to produce a page for each test. I would like to either be able to bold the exam title, bold the exam title, or make the text larger. I don't think I can use the latex commands like
\section*{}
to achieve this as R doesn't interpret these escape characters.

Thanks for your help!

Answer

you can use \section, you just need to be careful with the escaping. cat(sprintf("\section*{Exam: %s}", i) should do the trick

Comments