Search code examples
r-exams

In driver$read(file_tex[idj]) : length of exsolution and solutionlist does not match


i've got issues in the creating of an exam with the r-exams-package. It shows this error message:

In driver$read(file_tex[idj]) :   length of exsolution and solutionlist does not match

When i generate a exam with the function exams2html-function it shows me on the issued questions this:

issue type 1

or this:

issue type 2


Here is the syntax of "issue type 1", for the issued-questions showed above:

mc1_df <- data.frame(
  questions = 
              c(
                "Der Median und der Modus sind Maße der zentralen Tendenz, die auch für nominalskalierte Variablen verwendet werden können.",
                
                "Der Median ist gleich der zweiten Quartilsgrenze.",
                
                "Das arithmetische Mittel ist weniger anfällig für Ausreißer in den Daten als der Median.",
                
                "Für nominalskalierte Variablen lässt sich der Median nicht eindeutig berechnen.",
                
                "Für nominalskalierte Variablen lässt sich der Modalwert nicht eindeutig berechnen."
              )

  ,
  solutions = c(F,T,F,T,F))

The data.frame thats created with the syntax above is looking allright.

Im displaying it with the following syntax:

Question
========
Welche der folgenden Aussagen sind korrekt?

{r mc1 qlist, echo = FALSE, results = "asis"}
answerlist(mc1_df$questions, markup = "markdown")

Solution
========
{r mc1 slist, echo = FALSE, results = "asis"}
answerlist(mc1_df$solutions, markup = "markdown")

When i execute this chunks in a .RMD the answer- and solutionlist is showing properly, hence without any NA.

I use following meta-information:

Meta-information
================
exname: mc1
extype: mchoice
exsolution: `r mchoice2string(mc1_df$solutions)`
exshuffle: TRUE

Is there any way to avoid this issue?

p.s. I want to create a exam into moodlecloud. The html-version is only to check the syntax and the need for further questions.

best regards,

JSP


Solution

  • In principle, your example looks fine but it is hard to tell for sure because some of the code markup is not preserved exactly here on StackOverflow.

    My guess is that there is a missing space or line break somewhere. This may have the effect that either the first or last item from the question or answer list is not recognized correctly. R/exams has been improved over the last versions (including the current devel version on R-Forge) to avoid such issues but apparently not enough for your original file.

    I have set up the file mc1.Rmd from your question (see below for the full R/Markdown code). And using this both

    exams2html("mc1.Rmd")
    exams2moodle("mc1.Rmd")
    

    work fine, where file mc1.Rmd contains the following text. Note that including blank lines before/after code chunks may help to avoid problems/bugs with the parsing of the question/solution list.

    ```{r, include=FALSE}
    mc1_df <- data.frame(
      questions = c(
        "Der Median und der Modus sind Maße der zentralen Tendenz, die auch für nominalskalierte Variablen verwendet werden können.",
        "Der Median ist gleich der zweiten Quartilsgrenze.",
        "Das arithmetische Mittel ist weniger anfällig für Ausreißer in den Daten als der Median.",
        "Für nominalskalierte Variablen lässt sich der Median nicht eindeutig berechnen.",
        "Für nominalskalierte Variablen lässt sich der Modalwert nicht eindeutig berechnen."
      ),
      solutions = c(FALSE, TRUE, FALSE, TRUE, FALSE)
    )
    ```
    
    Question
    ========
    Welche der folgenden Aussagen sind korrekt?
    
    ```{r mc1 qlist, echo = FALSE, results = "asis"}
    answerlist(mc1_df$questions, markup = "markdown")
    ```
    
    Solution
    ========
    
    ```{r mc1 slist, echo = FALSE, results = "asis"}
    answerlist(mc1_df$solutions, markup = "markdown")
    ```
    
    Meta-information
    ================
    exname: mc1
    extype: mchoice
    exsolution: `r mchoice2string(mc1_df$solutions)`
    exshuffle: TRUE