2

Background

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

Problem

When a numeric exercise has a large solution, an error is thrown:

Error in string2num(exsolution) : 
  all numeric items must be finite and non-missing

Is this a bug or am I missing something out?

Minimal example

Here's a minimal exercise ("test-debug.Rmd") that provoked the error:

Question
========
Some text

Solution
========
Some solution

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

Meta-information
================
exname: test-debug
extype: num
exsolution: `r sol`

I used exams2html to render the exercise:

exams2html(file = "test-debug.Rmd",
           edir = path_to_exercise,
           dir = path_output)

System info

exams 2.4-0

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
Sebastian Sauer
  • 1,555
  • 15
  • 24
  • `exsolution: \`r fmt(sol, digits = 3)\`` may be worth trying, by comparison to one of their supplied examples: https://www.r-exams.org/assets/posts/2017-08-14-currency8//currency8.Rmd – Paul Stafford Allen Jan 05 '23 at 11:01
  • Hi Paul, I tried it and it solved the problem. I think you offered the solution. Thank you! – Sebastian Sauer Jan 05 '23 at 11:23
  • Great, I'll add it as an answer. – Paul Stafford Allen Jan 05 '23 at 11:39
  • 1
    Additional background: The problem is that `knitr` switches to scientific notation in the `exsolution` which is not read correctly by R/exams. The following answer has some more details: https://stackoverflow.com/questions/61254298/problem-with-round-function-in-rmd-exercise-file/61258974#61258974 – Achim Zeileis Jan 06 '23 at 08:54

1 Answers1

4
exsolution: `r fmt(sol, digits = 3)` 

Based on a review of one of the supplied examples on their site: r-exams.org/assets/posts/2017-08-14-currency8//currency8.Rmd

Paul Stafford Allen
  • 1,840
  • 1
  • 5
  • 16
  • 1
    See also the answer to the following question which discusses the same problem: https://stackoverflow.com/questions/61254298/problem-with-round-function-in-rmd-exercise-file/61258974#61258974 – Achim Zeileis Jan 06 '23 at 08:51