I just got one problem solved wrt exams2pdf()
, but ran right into another...
Consider the simple exercise file below (myquestion.Rmd
):
```{r, echo=FALSE, results="hide"}
x <- 1:5
y <- 1:5
png("myplot.png")
plot(x, y)
dev.off()
```
Question
========
What is this plot?
```{r, echo=FALSE, out.width='40%', fig.cap=""}
knitr::include_graphics("myplot.png", error = FALSE)
```
Answerlist
----------
* Scatterplot.
* Histogram.
Meta-information
================
exname: Q01
extype: schoice
exsolution: 10
exshuffle: FALSE
Executing exams2html("myquestion.Rmd")
works great. But exams2pdf("myquestion.Rmd")
does not render the plot.
I looked for answer and I did find some hints, in particular, referring to using the include_supplement()
function. It seems like the folder where the .tex file is rendered does not know where the .png image file is. But unfortunately nothing that I tried worked out. Can someone please show me what I need to do?
Importantly, I am building a big item bank (of a couple of hundred of items). I will need to be able to use either exams2nops
or exams2html
interchangeably, depending on the type of assignment that I need to generate. So the code should be flexible and work with either of these exams2xxx functions.
Thank you in advance.
TL;DR
Include such graphics in Markdown syntax rather than relying on knitr::include_graphics()
. In this case you can keep everything as it is and just change the question to:
Question
========
What is this plot?
![](myplot.png){width="40%"}
Details:
In order to be as modular as R/exams is, it needs to handle various conversions by itself. This is especially so because both .Rnw and .Rmd exercises are both supported and need to be handled consistently. This is why we do not rely on some of the knitr
features but have our own conversion tools.
Finally, include_supplement()
is relevant when including static files that have not been generated within the exercise itself (like your example does. An example for such a static graphic is provided in the Rlogo exercise.