For a corporate presentation I have created a xaringan-template that creates a presentation for individual regions based on the parameters passed in the yaml-header.
In the xaringan / RMarkdown document I create multiple plots which I write to a fixed directory through ggsave
with option type = "cairo"
. I then embed the plots in the slides using <img></img>
.
When using a script to render multiple presentations, the first presentation correctly displays our corporate fonts (Poppins Light and Poppins). However, the second and later presentations are unable to find Poppins Light (Poppins is rendered correctly) and result in multiple warnings:
In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... : font family 'Poppins Light' not found, will use 'sans' instead
I have been unable to create a reprex and cannot share my slides and/or figures but I have tried several things which may help to locate the issue:
- If I manually render the presentations one by one by changing the parameters manually and clicking the 'Knit' button in RStudio, everything runs as expected.
- If I render two presentations in the same R session through
rmarkdown::render()
, the figures in the second presentation are generated without Poppins Light. If I restart R (throughCTRL+SHIFT+F10
) between rendering two presentations, the figures in the second presentation are generated correctly. - If I randomly change the order in which the presentations are rendered, the first presentation still renders the figures correctly and the plots in the second and later presentations do not contain Poppins Light font and warnings are thrown.
- I do not rely on packages such as extrafont to display the fonts (exporting through
ggsave("path/to/file.png", plot, type = "cairo")
takes care of that). Loading Poppins and Poppins Light through extrafont does not solve the issue.
I have not been able to find a reference to this issue but must admit that I don't really know what to search for. My problem is different from knitr generating errors in document but generates figures correctly regardless because my figures are not generated correctly.
I'd like to know if this is a known issue and, if so, what can be done to mitigate it?