Let's say I've got 20 questions in a folder and I want to create an exam of 10 questions out of these 20, so that each student can have a different exam, using exams2pdf
or exams2nops
.
I'd also like a specific set of one or more exercises to always be included in the exam.
This would work:
library(exams)
fixed_question <- "questions/a.Rmd"
remaining_questions <- setdiff(paste0("questions/", dir(path = "questions"), fixed_question))
exam <- list(fixed_question, remaining_questions)
nsamp <- c(1,9)
exams2pdf(exam, n = 5, nsamp = nsamp)
but fixed_question
will always be the first question in the exam. Is there a way to shuffle the order of appearance of all 10 questions, including the fixed one(s)?
I also tried
exam <- list(c(fixed_question, sample(remaining_questions, 9)))
nsamp <- 10
exams2pdf(exam, n = 5, nsamp = nsamp)
Or even
exam <- list(sample(c(fixed_question, sample(remaining_questions, 9))))
but now I'm missing the other 10 questions.
Advanced shuffling patterns (as well as specific fixed patterns) can best be achieved by setting by an n-by-k matrix of file names, where
This can then be passed to exams2pdf()
or exams2nops()
and the arguments n=
and nsamp=
can then be dropped. Based on the example in the question, you can first select the vectors of exercise names:
library("exams")
fixed_question <- "a.Rmd"
remaining_questions <- setdiff(dir(path = "questions"), fixed_question)
Note that I have dropped the questions/
path from the names above. This is best added as the edir=
argument below.
Then you can:
remaining_questions
fixed_question
in the first positionexam <- replicate(5, sample(remaining_questions, 9))
exam <- rbind(fixed_question, exam)
exam <- t(apply(exam, 2, sample))
And then finally you call exams2pdf()
without the n
or nsamp
arguments (and here with the edir
argument as explained above).
exams2pdf(exam, edir = "questions/")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With