Home > Net >  How to include all elements of a vector in an exams2moodle or exams2pdf output?
How to include all elements of a vector in an exams2moodle or exams2pdf output?

Time:03-05

I am working on a simple code to find the square root of the following elements:

   dat <- c(4,9,16,25,36,49,64,81,100,121,144,169,196,225)
   num<-sample(dat ,1,replace=F)   

Parts of the seed file are configured like this:

 examen01<-c("SinRad.Rmd")
   semilla<-sample(100:1000, 1)
   set.seed(semilla) 

   exams2moodle(examen01,n=14,svg=TRUE,name="SinRadConRad",
              encoding="UTF-8",dir="salida",edir="ejercicios",
              mchoice = list(shuffle = TRUE,answernumbering = "ABCD",
              solution = FALSE,
              eval = list(partial = TRUE,rule = "none")))

I intend that, with n=14, all the responses to the options found in the "dat" vector are included, but I see that there are responses that are repeated.

How to achieve 14 answers for the 14 possibilities, without repeating or missing any?

Thank you very much

CodePudding user response:

Looking at the documentation, the following is stated regarding nsamp:

The number(s) of exercise files sampled from each list element of file. Sampling without replacement is used if possible. (Only if some element of nsamp is larger than the length of the corresponding element in file, sampling with replacement is used.)

So, if you add nsamp=14 in exams2moodle() you should get the proper behavior.

Here's my take using your code:

exams2moodle(examen01,n=14,nsamp=14,svg=TRUE,name="SinRadConRad",
             encoding="UTF-8",dir="salida",edir="ejercicios",
             mchoice = list(shuffle = TRUE,answernumbering = "ABCD",
             solution = FALSE,
             eval = list(partial = TRUE,rule = "none")))

CodePudding user response:

The exams2xyz() functions have been written to draw large numbers of random variations from sets of exercises. There is no dedicated functionality that draws a small number of deterministic variations. So in your case I would just draw, say, a hundred variations from the exercise template even if it can only yield 14 distinct versions. Sure, this wastes a bit of memory but not so much that I would worry about this.

Having said that, it is possible to set up a temporary file with a specific version of an exercise by using the expar() function. For example, expar("SinRad.Rmd", num = 4) would yield an exercise where the num parameter has been fixed to 4. Then in the same way you can cycle through the other 13 numbers you want. In the following post we also provide an expargrid() function that does this for all possible combinationso of parameters: Making deterministic versions of a parametrized question

Then you can run exams2moodle() on the resulting 14 deterministic exercise files.

  • Related