I’m observing a strange behavior when I try to output both text and a plot inside a loop in knitr.
When I run the below code, text and plot output are offset:
- the 1st text is not followed by any plot
- the 2nd text is followed by the 1st plot
- the 3rd text is followed by the 2ndt plot
- etc.
- the last text is followed by the second-last and the last plot
Is there any way to correct this, i.e. each text followed by its corresponding plot ?
```{r echo=FALSE}
for (i in 1:5){
cat("\nIteration number: ")
cat(i)
plot(1:i)
}
```
This is an old bug in the
evaluatepackage which has been fixed. See issue #403 for details. The solutions is FAQ 1.