diff --git a/DESCRIPTION b/DESCRIPTION index b38ccfc..7050973 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,8 @@ Imports: rlang, sf, stringr, - tidyr + tidyr, + withr Suggests: ggplot2, ggspatial, diff --git a/R/utils-map.R b/R/utils-map.R index 329789b..0c4f01a 100644 --- a/R/utils-map.R +++ b/R/utils-map.R @@ -492,27 +492,31 @@ create_polar_markers <- } save_plot <- function(data, url) { - grDevices::pdf(NULL) - - plot <- fun(data) - - grDevices::png( - filename = url, - width = width * 300, - height = height * 300, - res = 300, - bg = "transparent", - type = "cairo", - antialias = "none" + # suppress Rplots.pdf + withr::with_cairo_pdf( + tempfile("PDFSINK"), + { + # create plot + plot <- fun(data) + + # save plot + grDevices::png( + filename = url, + width = width * 300, + height = height * 300, + res = 300, + bg = "transparent", + type = "cairo", + antialias = "none" + ) + print(plot) + grDevices::dev.off() + + # return plot + return(plot) + } ) - print(plot) - - while (grDevices::dev.cur() != 1L) { - grDevices::dev.off() - } - - return(plot) } if (ncores == 1L) { diff --git a/tests/testthat/test-theme_static.R b/tests/testthat/test-theme_static.R index d694bc7..71842a8 100644 --- a/tests/testthat/test-theme_static.R +++ b/tests/testthat/test-theme_static.R @@ -1,7 +1,5 @@ test_that("theme can be added to a ggplot2 object", { - options(device = "cairo") - testthat::expect_no_error( - plt <- ggplot2::ggplot() + theme_static() + ggplot2::ggplot() + theme_static() ) })