R/methods.r

Defines functions grid.draw.wpplot as.grob.wpplot print.wpplot

##' @method print wpplot
##' @import utils
##' @export
print.wpplot <- function(x, ...) {
  #if (Sys.getenv("TERM_PROGRAM") == "vscode") {
  #  p <- ggplotify::as.ggplot(x)
  #  print(p)
  #} else {
  #    browseURL(svg2tempfile(x$svg))
  #}

  print(ggplotify::as.ggplot(x))

}


##' @importFrom ggplotify as.grob
##' @method as.grob wpplot
##' @importFrom grid rasterGrob
##' @export
as.grob.wpplot <- function(plot, ...) {
  f <- svg2tempfile(plot$svg)
  p <- rsvg::rsvg_nativeraster(f)
  rasterGrob(p)
}

##' @method grid.draw wpplot
##' @importFrom grid grid.draw
##' @export
grid.draw.wpplot <- function(x, recording = TRUE) {
  grid::grid.draw(as.grob.wpplot(x), recording = recording)
}

Try the wikiprofiler package in your browser

Any scripts or data that you put into this service are public.

wikiprofiler documentation built on June 8, 2025, 1:29 p.m.