Search code examples
r-exams

How to fix the R/exams error "could not find function answerlist"


I have created an R/exams question in R/Markdown format. When I try to compile and then take it to exams2moodle and / or exams2pdf, I get the following error message:

Error in answerlist (questions, markup = "markdown"): could not find function answerlist.

The exercise is:

```{r, data generation, echo = FALSE, results = "hide"}
#1a.GENERACION DE DATOS. ASIGNACION/DEFINICION DE VARIABLES. CUELLO
a1<-sample(seq(from = 100, to = 250, by = 2), 10)
casilla1<-min(a1)
casilla2<-max(a1)
increm<-casilla2-casilla1
a2<-sample(seq(from = casilla2, to = casilla2+increm, by = 2))
casilla3<-min(a2)
casilla4<-max(a2)
a3<-sample(seq(from = casilla4, to = casilla4+increm, by = 2))
casilla5<-min(a3)
casilla6<-max(a3)

#1b.GENERACION DE DATOS. ASIGNACION/DEFINICION DE VARIABLES. CUERPO
crpizq<-casilla6*1.5
c1<-sample(seq(from = crpizq, to = crpizq+increm, by = 2))
casilla7<-min(c1)
casilla8<-max(c1)
c2<-sample(seq(from = casilla8, to = casilla8+increm, by = 2))  
casilla9<-min(c2)
casilla10<-max(c2)
c3<-sample(seq(from = casilla10, to = casilla10+increm, by = 2))
casilla11<-min(c3)
casilla12<-max(c3)

#1c.GENERACION DE DATOS. ASIGNACION/DEFINICION DE VARIABLES. PRECIO
precio1<-sample(seq(from=20000, to=40000, by=500), 1)
precio2<-precio1+15000
precio3<-precio2+15000
preciopregunta<-sample(c(precio1,precio2,precio3), 1)

#2a.GENERACION DE PREGUNTA(S)/RESPUESTA(S). ASIGNACION/DEFINICION DE VARIABLES
cuellop1<-sample(seq(from = casilla1,to = casilla2-1, by = 2), 1)
cuerpop1<-sample(seq(from = casilla7,to = casilla8-1, by = 2), 1)
cuellop2<-sample(seq(from = casilla3,to = casilla4-1, by = 2), 1)
cuerpop2<-sample(seq(from = casilla9,to = casilla10-1, by = 2), 1)
cuellop3<-sample(seq(from = casilla5,to = casilla6-1, by = 2), 1)
cuerpop3<-sample(seq(from = casilla11,to = casilla12-1, by = 2), 1)

questions<-solutions<-explanations<-NULL
if(preciopregunta==precio1) {
   questions[1]<-paste("Vasija de " ,cuellop1, " mm en contorno de cuello y ", 
                    cuerpop1, " mm en contorno de cuerpo.")
   solutions[1]<-TRUE
   explanations[1]<-"."
   questions[2]<-paste("Vasija de " ,cuellop1, " mm en contorno de cuello y ", 
                    cuerpop2, " mm en contorno de cuerpo.")
   solutions[2]<-FALSE
   explanations[2]<-"."
   questions[3]<-paste("Vasija de " ,cuellop2, " mm en contorno de cuello y ", 
                    cuerpop3, " mm en contorno de cuerpo.")
   solutions[3]<-FALSE
   explanations[3]<-"."
   questions[4]<-paste("Vasija de " ,casilla1, " mm en contorno de cuello y ", 
                    casilla8, " mm en contorno de cuerpo.")
   solutions[4]<-FALSE
   explanations[4]<-"."
   orden<-sample(1:4)
   questions<-questions[orden]
   solutions<-solutions[orden]
   explanations<-explanations[orden]
   } else if (preciopregunta==precio2) {
   questions[1]<-paste("Vasija de " ,cuellop2, " mm en contorno de cuello y ", 
                    cuerpop2, " mm en contorno de cuerpo.")
   solutions[1]<-TRUE
   explanations[1]<-"."
   questions[2]<-paste("Vasija de " ,cuellop1, " mm en contorno de cuello y ", 
                    cuerpop2, " mm en contorno de cuerpo.")
   solutions[2]<-FALSE
   explanations[2]<-"."
   questions[3]<-paste("Vasija de " ,cuellop2, " mm en contorno de cuello y ", 
                    cuerpop3, " mm en contorno de cuerpo.")
   solutions[3]<-FALSE
   explanations[3]<-"."
   questions[4]<-paste("Vasija de " ,casilla3, " mm en contorno de cuello y ", 
                    casilla10, " mm en contorno de cuerpo.")
   solutions[4]<-FALSE
   explanations[4]<-"."
   orden<-sample(1:4)
   questions<-questions[orden]
   solutions<-solutions[orden]
   explanations<-explanations[orden]
   } else {
   questions[1]<-paste("Vasija de " ,cuellop3, " mm en contorno de cuello y ", 
                    cuerpop3, " mm en contorno de cuerpo.")
   solutions[1]<-TRUE
   explanations[1]<-"."
   questions[2]<-paste("Vasija de " ,cuellop1, " mm en contorno de cuello y ", 
                    cuerpop2, " mm en contorno de cuerpo.")
   solutions[2]<-FALSE
   explanations[2]<-"."
   questions[3]<-paste("Vasija de " ,cuellop2, " mm en contorno de cuello y ", 
                    cuerpop3, " mm en contorno de cuerpo.")
   solutions[3]<-FALSE
   explanations[3]<-"."
   questions[4]<-paste("Vasija de " ,casilla5, " mm en contorno de cuello y ", 
                    casilla12, " mm en contorno de cuerpo.")
   solutions[4]<-FALSE
   explanations[4]<-"."
   orden<-sample(1:4)
   questions<-questions[orden]
   solutions<-solutions[orden]
   explanations<-explanations[orden] }
```
The table shows the relationship between prices and measurements that an artisan handles in the sale of vessels:

|       Contorno del cuello (mm)        |        Contorno del cuerpo (mm)         |       Precio        |
|:-------------------------------------:|:---------------------------------------:|:-------------------:|
| [**`r casilla1`** , **`r casilla2`**) |  [**`r casilla7`** , **`r casilla8`**)  | $\$$**`r precio1`** |
| [**`r casilla3`** , **`r casilla4`**) | [**`r casilla9`** , **`r casilla10`**)  | $\$$**`r precio2`** |
| [**`r casilla5`** , **`r casilla6`**) | [**`r casilla11`** , **`r casilla12`**) | $\$$**`r precio3`** |

Question
========

Which of the following pots has a price of $\$$**`r preciopregunta`**?

```{r, questionlist, echo = FALSE, results = "asis"}
answerlist(questions, markup = "markdown")
```

Solution
========
```{r, solutionlist, echo = FALSE, results = "asis"}
answerlist(ifelse(solutions,"True","False"),explanations, markup = "markdown")
```

Meta-information
================
extype: schoice 
exsolution:`r mchoice2string(solutions)` 
exname: Vas

Solution

  • I cannot replicate this problem using the exercise you provided, for me the code works. You should move the text with the table into the Question section, though.

    What might have caused the problem is that you did not fully load and attach the R package exams via library("exams") and only used the fully-qualified exams::exams2pdf(...) without attaching the package. If so, then you also need the fully-qualified exams::answerlist(...) and exams::mchoice2string(...) etc. to use the functions from the package. (Personally, I load and attach the package with library("exams") before compiling any exercises.)