I'm automating a presentation and want to create a slide for each image in a directory (the image filenames are all .png files with three-character names).
This works as desired to test that the slide with title and image will render:
```{r, results="asis", out.width="900px"}
plot_files <- list.files(paste0(mydir, "/plots"))
i <- 1
cat("\n\n##", substr(plot_files[i], 1, 3), "\n\n", sep="")
knitr::include_graphics(paste0(dir, "/plots/", plot_files[i]))
```
But when I wrap the above into a for
loop...
```{r, results="asis", out.width="900px"}
plot_files <- list.files(paste0(mydir, "/plots"))
for (i in 1:length(plot_files)) {
cat("\n\n##", substr(plot_files[i], 1, 3), "\n\n", sep="")
knitr::include_graphics(paste0(dir, "/plots/", plot_files[i]))
}
```
...each of the slides is correctly generated with the title, but the images no longer render. Any ideas why wrapping the code in the loop would cause the image rendering to fail?