-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture.R
35 lines (32 loc) · 911 Bytes
/
capture.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#' 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
}