1

When creating worksheets with exams2pdf() from R/exams, I like to repeat an exercise file multiple times to yield different numbers. However, when I include two plots in an exercise (e.g., one in the question and one in the solution) this yields:

Error in exm[[dups[j]]] : subscript out of bounds

A reproducible example is included below. It works with one plot, and it works if I don't repeat the question. Also, the problem can be avoided by making multiple copies of a simple.Rmd (say simple1.Rmd and simple2.Rmd with different chunk names in each copy) but it seems there should be a better way.

The Rmd file: simple.Rmd

Question
========
A question.
```{r drawit}
x = (-330):330/100
y = dnorm(x)
plot(x,y)
```

Solution
========
Let's redraw...
```{r drawagain}
x2 = (-330):330/100+100
y2 = dnorm(x2,mean=100,sd=1)
plot(x2,y2)
```

Meta-information
============
extype: num
exsolution: 10
exname: calc

And the replication R code:

library("exams")
q1 = "simple.Rmd"
probs = c(q1,q1)
exams2pdf(probs)

The Rmd file will knit fine (with two plots) but running the code above yields the above mentioned

Error in exm[[dups[j]]] : subscript out of bounds
Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49

1 Answers1

0

Thanks for reporting this, this is a bug in exams2pdf()! Single duplicated supplement names were already corrected but the case of multiple duplicated supplement names was not. I've just committed a fix to the repository on R-Forge that addresses the issue.

It would be great if you could install the development version of the package from R-Forge to test whether the fix also works correctly on your real use-case. You can install from within R via:

install.packages("exams", repos="http://R-Forge.R-project.org")
Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • Thanks for the follow-up. Please also accept the answer here on Stackoverflow so that it gets flagged as solved. – Achim Zeileis Oct 08 '19 at 01:47
  • This is probably a separate question, but I notice a ".image" text after the 2nd, 3rd, 4th instances of a figure. Any thoughts on this? – TwelveFifths Oct 08 '19 at 11:00
  • Thanks for the pointer, I just fixed the problem with my fix on R-Forge. Hopfully for real now. Please try again by installing the latest `exams` version. – Achim Zeileis Oct 09 '19 at 00:09