SVG vdiffr testing

For some situations, I need to use golden tests for figures that aren’t made by ggplot or base or otherwise have a print() method as required by vdiffr::write_svg(). Specifically, I encounter this issue with networks created by DiagrammeR, which are html. The solution is to write a custom writer function. Note that for this to work, we also need to install DiagrammeRsvg and rsvg; they are only suggests for DiagrammeR and so are not automatically installed.

svgnetwriter <- function(plot, file, title = "") {
  plot |>
    DiagrammeR::export_graph(file_name = paste0(file))
}

Then we can call expect_doppleganger

vdiffr::expect_doppelganger(title = "plot_name", fig = plot_object, 
                            writer = svgnetwriter)

This is a bit confusing, because the order of arguments changes for expect_doppleganger and writer, and change meaning as well. The title argument to expect_doppleganger becomes the file argument of writer (with '.svg' appended). So writer needs plot, then filename, then a title (which I skip here). The file should not have .svg on it, as that gets added automatically to "plot_name" in expect_doppleganger. The title argument for writer is only used for ggplot objects in vdiffr::print_plot().