R/capture.R

Defines functions ps_capture

Documented in ps_capture

#' Capture PlanScore Graphs
#'
#' @param link plan_url output from `ps_upload()` functions
#' @param path path to save copy of graphs in, likely ending in `.png`
#'
#' @return path to screenshot
#' @export
#'
#' @concept results
#'
#' @examplesIf interactive()
#' # often times out
#' url <- 'https://planscore.org/plan.html?20221127T213653.168557156Z'
#' tf <- tempfile(fileext = '.png')
#' ps_capture(url, path = tf)
ps_capture <- function(link, path) {
  if (missing(link)) {
    cli::cli_abort('{.arg link} is required.')
  }

  if (is.list(link) && 'plan_url' %in% names(link)) {
    link <- link[['plan_url']]
  }

  if (missing(path)) {
    cli::cli_abort('{.arg path} is required.')
  }

  webshot2::webshot(url = link, file = path)
  # # must close the supervisor on non-windows, doesn't close by default
  # if (Sys.info()[["sysname"]] != "Windows") {
  #   processx::supervisor_kill()
  # }
  path
}

Try the planscorer package in your browser

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

planscorer documentation built on Sept. 24, 2024, 5:08 p.m.