Search code examples
r-exams

R/exams, numerical to single choice conversion


I created a dynamic single choice question using num_to_schoice() function. I want to display 4 answers, 3 of which are typical errors.

An example:

sol<-300
wrong1 <-200
wrong2 <-100
wrong3<-400 
sc <- num_to_schoice(sol, wrong = c(wrong1,wrong2,wrong3), digits = 0)

Above creates 5 answers. How can I force it to display 4 answers? More specifically, is there a way to prevent R/exams from calculating additional wrong answers?

Thanks


Solution

  • If you don't need any ranodmly-generated wrong answers, then don't use num_to_schoice(). It's main purpose is generating some wrong answers in a certain range and with a certain delta.

    If you already have all wrong solutions you need you can simply insert the answer list using a code chunk with:

    answerlist("$", c(sol, wrong1, wrong2, wrong3), "$", sep = "", markup = ...)
    

    where ... would either be "markdown" or "latex" depending on the format of your exercise. (You may also want to omit the math markup with $. But num_to_schoice() includes it.)

    In the metainformation you just need to set exsolution to 1000 and exshuffle to TRUE so that the answer list is shuffled randomly for each exercise.