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:
- It is clear to
exams2pdf()
and hence contained in its corresponding meta-information that there are four different exams with different orders of the exercises.
- The fact that the exercises are exactly identical across exams is only implicitly stored - by the fact that the seeds are the same.