I recently discovered the R/exams package and I found it very useful to create exercises that I use with moodle.
However, it is not clear to me how to use it to produce a given number of different exercises from a single .Rmd file. Assume that I create 4 different parameter sets to be used in 4 different exercises. Here is my data generation section:
{r data generation, echo = FALSE, results = "hide"}
data=read.csv(header=T,text="
r,b,g,p
.05,1.3,.04,.03
.04,1.2,.05,.025
.035,1.1,.02,.03
.025,1.25,.015,.025")
i = sample(1:nrow(data),1)
dd=data[i,]
This randomly assigns a row from data to the variable dd, which is used to produce the exercise. Then, by setting the argument n in exams2moodle, I can randomly generate as many exercises as I want, of 4 different types.
However, what if instead I want to have exactly 4 exercises each using a different set? Using the option n=4 as an argument of `exams2moodle', the 4 exercises picked up at random will likely involve repetition and will not be necessarily different one from another.
Disclaimer: R/exams has been mainly designed for the setup where you generate large number of different exercises where it is not necessary/easy/feasible to track every possible random variation. Hence there is no built-in infrastructure to easily generate every possible variation of an exercise. I typically do not worry that some of the many variations I generate might be identical "by chance" - as long as there is still sufficient random variation.
Workaround: However, there is the
expar()function that creates temporary copies of an exercise with certain (scalar) variables fixed. See?exparfor further details. Using this you could do:This gives you a temporary file that you can use as input for all
exams2xyz()generators. So you can use this withi = 1up toi = 4to give you all four versions of your exercise.Illustration: I'm using the countrycodes exercise template shipped along with the package. This also has a finite set of variable combinations from which some
iis sampled (in 1, ..., 167). To get the first four of these you can do:Exam
What is the three-letter country code (ISO 3166-1 alpha-3) for Angola?
What is the three-letter country code (ISO 3166-1 alpha-3) for Albania?
What is the three-letter country code (ISO 3166-1 alpha-3) for Argentina?
What is the three-letter country code (ISO 3166-1 alpha-3) for Armenia?
Instead of using
exams2html()you can also useexams2moodle()or any otherexams2xyz()interface.