svenhalvorson svenhalvorson - 1 year ago 100
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:



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



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
to achieve this as R doesn't interpret these escape characters.

Thanks for your help!

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download