-
-
Save fototo/3c0c67ca07c2ae38f3b0 to your computer and use it in GitHub Desktop.
Example code for automatically generating R exercises and exams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Load library: | |
library("exams") | |
## exam questions: | |
myexamlist<-list("pnorm1","sesamplesize1multiplechoice") | |
## output directory | |
## create new test dir if one does not exist: | |
files.list<-system("ls",intern=TRUE) | |
if(length(unique(files.list=="ExampleExamSU2015"))==1){ | |
system("mkdir ExampleExamSU2015") | |
} | |
odir <- paste(getwd(),"/ExampleExamSU2015",sep="") | |
## ID generator function; | |
## labels each test version (for easier grading): | |
## only the last digit tells you what version it is, | |
## the rest of the numbers are distractors, to make | |
## it difficult for students to figure out which version | |
## they have. Change this as you please to mask your version no. | |
getID <- function(i) { | |
paste("Example Exam SU 2015, date: ",date(), | |
gsub(" ",abs(round(rnorm(1,mean=20000,sd=20),digits=0)), | |
format(i, width = 2)),sep="") | |
} | |
## testing: | |
getID(1) ## version 1 | |
getID(2) ## version 2 | |
## generate exams | |
#set.seed(1090) ## uncomment only if you want deterministic behavior | |
## how many different versions of exams? | |
num.versions<-2 | |
sol <- exams(myexamlist, n = num.versions, | |
dir = odir, template = c("test", "solutiontest"), | |
nsamp=1, | |
header = list(ID = getID, Date = Sys.Date())) | |
## generated files | |
list.files(odir) | |
## meta-information | |
print(sol, 1) | |
print(sol, "test1") | |
## customize printed meta-information | |
#mycontrol <- list(mchoice.print = list(True = LETTERS[1:5], False = "_")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment