This is a bit of a two-parter, which I only realised after I started explaining it here.
I’m producing a large and fairly complicated markdown book with multiple chapters and child files that all feed into one another (and so I’m not sure how much of a reprex I can provide, sorry). I’m using knitr::include_graphics
to show existing .png plots, and also using ggplot to create plots using code. There are hundreds of images that get pulled/created.
For some reason, whenever I knit to html using bookdown::render_book
, the image files get saved in three different places. I’ve set knitr::opts_chunk$set(fig.path = "images/")
, and that works as expected, with an “images” folder created in my project directory. However, I also get an images folder within the _book folder where the html files are saved. These two folders are identical, except the files get created a few minutes apart (roughly the time it takes to knit). The only files in these folders are the ones from ggplot.
So, Question 1 is, What might be causing this duplication?
Meanwhile, the images pulled using include_graphics
end up somewhere else entirely, in a directory that seems to be created according to a directory path that’s used in the project.
The .png files already exist in (e.g.) project/out/sdm/. In the markdown, I use out_dir <- "project/out/sdm"
to collect them, i.e. include_graphics(fs::path(out_dir, "best.png")
. That works fine, and the html document is working as expected. However, best.png gets duplicated not into the images folder as above, but into [my markdown folder]/out_dir.
Question 2, why are these not all in the same place, and why is my out_dir being used to save the images?