Search code examples
rr-exams

Numeric questions with large tolerance throw error


Background

R/exams is a great tool for generating exams for students.

Problem

When a numeric exercise has a large tolerance (extol), an error is thrown:

Error in if (!is.null(extol) && any(extol < 0)) { : 
  missing value where TRUE/FALSE needed

Is this a bug or am I missing something out?

Minimal example

Here's a minimal exercise that provoked the error:

Question
========
Some text

Solution
========
Some solution

```{r}
sol <- 1e4
sol_tol <- 1e4
```

Meta-information
================
exname: test-debug
extype: num
exsolution: `r fmt(sol, 3)`
extol: `r sol_tol`

I used exams2html to render the exercise:

exams2html(file = "test-debug.Rmd",
           edir = "exercises",
           dir = "/.")

System info

exams 2.4-0


Solution

  • You need to make sure that both the exsolution and the extol actually contain numbers only. However, depending on the scipen option, large numbers might be converted to strings containing scientific notation.

    In your example, you avoid the scientific notation by using the fmt() function in exsolution. But as you do not use fmt() in extol, this gets rendered into a string and not just a number.

    The problem and corresponding solution are explained in a bit more detail in: Problem with round() function in .Rmd exercise file

    In short, either assure that scipen is sufficiently high or use a formatter like fmt() that assure to display it's input as a plain number only.