rggplot2r-markdownpkgdownsvglite

How to successfully use {pkgdown} when `svglite` graphics device is used


To address an issue in my R package, I wish to try out an svglite graphics device for rendering ggplot plots:

knitr::opts_chunk$set(dev = "svglite")

But, if I do so, the {pkgdown} workflow fails (failure log) with the warning messages:

1: 'mode(bg)' differs between new and previous
     ==> NOT changing 'bg' 
2: 'mode(bg)' differs between new and previous
     ==> NOT changing 'bg' 

If I understand correctly, these warning messages are coming from par(), which is complaining about not being able to change the background colour (bg). But I am not explicitly calling par(), nor am I changing the background colour for the plot in question.

So I wish to know why exactly am I getting this error and how to resolve it?


Solution

  • I think you have a font mismatch issue.

    Download necessary font files, make sure in the source package and register the necessary them with package 'systemfonts' and function systemfonts::register_font(). This is the right thing to do for packages 'svglite', 'ragg' (and 'ggiraph').

    It looks like you have "greek" variant on your machine, but not on the GA remote machine.

    In your package, I would add a new 'Suggests' entry with gdtools that can help you download the font and register it seamlessly (disclaimer, I am the author, but I really think it makes things easier). And in the vignette, before any graph production with 'ragg' or 'svglite', add the following code:

    gdtools::register_gfont(family = "Open Sans", subset = c("latin", "latin-ext", "greek"))