2

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

4
  • extol contains NA values. This is not related to it being large. (I'm not familar with the exams package.)
    – Roland
    Commented Mar 17, 2023 at 11:38
  • 2
    I guess what happens: knitr switched to scientific notation and then the tolerance cannot be corrected to numeric. Adding fmt() should do the trick. Will check when I'm on a computer. Commented Mar 17, 2023 at 12:38
  • @AchimZeileis: Yes! fmt() did the trick. Thanks a lot! Commented Mar 17, 2023 at 13:14
  • @Roland: In my case, no NAs in sol_tol or extol. Commented Mar 17, 2023 at 13:26

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.