Reputation: 21
I am using the R package exams
. I am trying to generate four versions of exactly the same exam with R/exams, but with each having a different question order. Also, I would like to have full control over the order. For example, if I have four questions (1-2-3-4)
, I want to generate versions: (2-3-1-4)
, (3-1-4-2)
, (2-1-3-4)
, (1-4-2-3)
. Here is the code I could use:
base.order = list("tstat2.Rmd","Cholesky.Rmd","boxhist.Rmd","confint.Rmd")
order1 = base.order[c(2,3,1,4)]
order2 = base.order[c(3,1,4,2)]
order3 = base.order[c(2,1,3,4)]
order4 = base.order[c(1,4,2,3)]
set.seed(1322)
exams2pdf(order1,template="exam")
set.seed(1322)
exams2pdf(order2,template="exam")
set.seed(1322)
exams2pdf(order3,template="exam")
set.seed(1322)
exams2pdf(order4,template="exam")
The problem is that the same question in different versions makes use of different numbers. How can this be solved?
Upvotes: 1
Views: 668
Reputation: 17183
An alternative solution to this problem is facilitated by today's additions to the development version of R/exams on R-Forge. It can be installed with install.packages("exams", repos="http://R-Forge.R-project.org")
.
The new version allows to supply a matrix of exercise file
s where the rows correspond to different exams and the columns to the exact desired order of exercises within the exam. Furthermore, a corresponding matrix of random seed
s can be supplied that are being set immediately before processing the corresponding exercise. Usually, the seeds would vary across exams but, of course, this can also be used to fix the seeds to be identical across exams as desired here.
First, we define the vector of exercises and the matrix of desired permutations:
exc <- c("tstat2.Rmd","cholesky.Rmd","boxhist.Rmd","confint.Rmd")
idx <- rbind(c(2, 3, 1, 4), c(3, 1, 4, 2), c(2, 1, 3, 4), c(1, 4, 2, 3))
Then, we generate a random vector of random seeds (of course, you can also pre-select the desired seeds manually):
set.seed(1)
rsd <- sample(1:9999, 4)
Based on these we can set up the exercise files and seeds as matrices
exc <- exc[idx]
rsd <- rsd[idx]
dim(exc) <- dim(rsd) <- dim(idx)
exc
## [,1] [,2] [,3] [,4]
## [1,] "cholesky.Rmd" "boxhist.Rmd" "tstat2.Rmd" "confint.Rmd"
## [2,] "boxhist.Rmd" "tstat2.Rmd" "confint.Rmd" "cholesky.Rmd"
## [3,] "cholesky.Rmd" "tstat2.Rmd" "boxhist.Rmd" "confint.Rmd"
## [4,] "tstat2.Rmd" "confint.Rmd" "cholesky.Rmd" "boxhist.Rmd"
rsd
## [,1] [,2] [,3] [,4]
## [1,] 8004 4775 1017 9725
## [2,] 4775 1017 9725 8004
## [3,] 8004 1017 4775 9725
## [4,] 1017 9725 8004 4775
And then finally the exam can be generated with any template
, e.g.:
library("exams")
exams2pdf(exc, seed = rsd, template = "exam.tex")
Compared to the other answer that generates a single exam with four different templates:
exams2pdf()
and hence contained in its corresponding meta-information that there are four different exams with different orders of the exercises.Upvotes: 1
Reputation: 17183
For producing different versions of the same exam using exams2pdf()
from R/exams, the easiest solution is to use different templates. And to fix the ordering you can replace the
%% \exinput{exercises}
with the \input{}
statements for the desired exercises, e.g.,
\input{exercise2}
\input{exercise3}
\input{exercise1}
\input{exercise4}
Originally, we introduced this feature to allow for text between certain exercises or further special formatting. But it can also be used to change the ordering. At
https://R-Forge.R-project.org/forum/attachment.php?attachid=395&group_id=1337&forum_id=4377 I put up a .zip file with plain .tex
files in four versions (A-D) with the different desired orderings. With this you can do:
base.order <- list("tstat2.Rmd","cholesky.Rmd","boxhist.Rmd","confint.Rmd")
exams2pdf(base.order,
template = c("plainA", "plainB", "plainC", "plainC", "plainD"))
A potential caveat is that this stores the meta-information only once. Thus, when correcting the exam, you have to re-permute the solutions because the permutations are not stored in the meta-information. A possible strategy could be to write a small wrapper function to exams2pdf()
that (a) creates a matrix with the permutations, (b) generates the modified .tex
templates, (c) stores all necessary metainformation.
Upvotes: 0