unntested draft
rstudio_run_script_as_job <- function(
name = NULL,
wd = NULL,
import_env = FALSE
) {
require_namespace("rstudioapi")
if (!(interactive() && rstudioapi::isAvailable())) {
return(invisible())
}
if (is.null(wd)) {
wd <- if (package_available("here")) {
here::here()
} else {
message("using current working directory; suggest installing {here}")
getwd()
}
}
active_file <- rstudioapi::getSourceEditorContext()$path
name <- name %||% paste(
file_name(active_file),
format(Sys.time())
)
rstudioapi::jobRunScript(
path = active_file,
name = name,
workingDir = wd,
importEnv = import_env
)
}
unntested draft