jobscript: Run code as RStudio background task

Description Usage Arguments Value Examples

View source: R/jobs.R

Description

Write the code provided to code or copied to the clipboard to a file indicated by filename in the directory indicated by dir and run it as a background task in RStudio

Usage

1
2
3
4
5
6
7
8
9
jobscript(
  code,
  filename,
  dir = NULL,
  workingDir = getwd(),
  exportEnv = .GlobalEnv,
  importEnv = TRUE,
  ...
)

Arguments

code

expression to be written to file. Either one created with expr, or provided wrapped in {}. If no code is provided, the clipboard will be read.

filename

character filename

dir

character vector of directories

workingDir

The working directory in which to run the job. When NULL (the default), the parent directory of the R script is used.

exportEnv

The name of the environment in which to export the R objects created by the job. Use "" (the default) to skip export, "R_GlobalEnv"' to export to the global environment, or the name of an environment object to create an object with that name.

importEnv

Whether to import the global environment into the job.

...

Arguments passed on to rstudioapi::jobRunScript

path

The path to the R script to be run.

name

A name for the background job. When NULL (the default), the filename of the script is used as the job name.

encoding

The text encoding of the script, if known.

Value

character the path to the file invisibly and once the task completes, any code results (as would be returned if using the background tasks feature directly)

Examples

1
2
3
4
5
6
jobscript({
# long running code
Sys.sleep(10)
out <- "I returned"
}, filename = "ex.R", exportEnv = "R_GlobalEnv")
file.remove("ex.R")

yogat3ch/jobs documentation built on Dec. 23, 2021, 8:17 p.m.