0

I'm having trouble writing a cloze question with the exams package in R. I tried to stick close to the boxhist.Rmd example, but something must be wrong. the weird thing is that knitting the Rmd in rstudio displays all components ok - it's just that the html output is blank for the questions? any ideas much appreciated! here is my Rmd file, that I give to exams:::exams2html:

```{r data generation, echo = FALSE, results = "hide"}
m = sample(c(-1,0,5),1)
s = sample(c(1,10,20))
x = rnorm(mean = m, sd = s, n = 100)
write.csv(x, file="sumstats.csv",quote = FALSE,row.names = FALSE)
questions <- rep(list(""), 5)
solutions <- rep(list(""), 5)
explanations <- rep(list(""), 5)
type <- rep(list("num"),5)

questions[[1]] <- "What is the Interquartile range of $x$?"
questions[[2]] <- "What is the Variance of $x$?"
questions[[3]] <- "What is the standard deviation of $x$?"
questions[[4]] <- c("The standard deviation is *always* smaller than the variance.","The standard deviation is *NOT always* smaller than the variance.")
questions[[5]] <- "What is the median of $x$?"

solutions[[1]] <- round(IQR(x),3)
solutions[[2]] <- round(var(x),3)
solutions[[3]] <- round(sd(x) ,3)
solutions[[4]] <- mchoice2string(c(FALSE,TRUE))
solutions[[5]] <- round(median(x),3)

type[[4]] <- "schoice"

explanations[[1]] <- "Function `IQR`"
explanations[[2]] <- "Use `var(x)`"
explanations[[3]] <- "`sd(x)`"
explanations[[4]] <- "$\\sqrt{x}$ is not always smaller than $x$. Try $x=0.5$!"
explanations[[5]] <- "`median(x)`"

```

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

Solution
========

```{r solutionlist, echo = FALSE, results = "asis"}
answerlist(paste(unlist(explanations), ".", sep = ""), markup = "markdown")
```



Meta-information
================
extype: cloze
exsolution: `r paste(solutions, collapse = "|")`
exclozetype: `r paste(type, collapse = "|")`
exname: sumstats
extol: 0.05
Florian Oswald
  • 5,054
  • 5
  • 30
  • 38

1 Answers1

1

You omitted the

Question
========

markup before the question list. Actually, I'm surprised that this works at all, given that R/exams does not know where the question is...

Also, the length of the unlisted questions (6) needs to match the length of the unlisted solutions (currently only 5). This may be necessary in some learning management systems to provide feedback on the individual sub-items.

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • d'oh. i can't believe i couldn't figure that out. :-/ thanks for the great package! – Florian Oswald Oct 04 '18 at 07:28
  • These things happen when trying new things...and that's what Q&A sites and forums are for :-) As I said: I'm surprised that R/exams did not throw an error. I have to look into that and preferably issue an informative error message in such a situation. – Achim Zeileis Oct 04 '18 at 07:30