Skip to content

RStudio job sourcing #196

@jmbarbone

Description

@jmbarbone

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
  )
}

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions