I use Rnw files to create exams for my students, I put separate quiz into child Rnw file and include them in the main Rnw in the way
<<child="xx.Rnw">>@
The xx.Rnw contains the problem statement and also the answer. I want to have two versions of the exam, one without the answer and one with the answer. Which means I need something that could conditionally generate two types of pdf.
The answer part is a mixer of <<>>@ code and latex. Anyone has a good idea how to do this in an agile way? Thanks!
For each problem statement you could create 2 child rnw chunks. The first chunk calls the rnw without the answers and the second chunk calls the rnw with the answer. At the beginning of the rnw document, create 2 variables called
hide_answer
andshow_answer
and set theeval
chunk option of the child rnw chunks that omit the answer tohide_answer
and set theeval
chunk option of the child rnw chunks that show the answer toshow_answer
.Then all you have to do is set the variables to
TRUE
orFALSE
to generate the desired PDF.