export: What to return from a job

View source: R/job_utils.R

exportR Documentation

What to return from a job

Description

Call this function as the last line in job::job() to select what is exported back into globalenv(). export() does nothing if called in any other context.

Usage

export(value = "changed", file = NULL)

Arguments

value

What to return. One of:

  • "all": Return everything, including imports

  • "changed" (default): Return all variables that are not identical to import.

  • "new": Return only new variable names.

  • c(var1, var2, ...): Return these variable names.

  • NULL or "none": Return nothing. This is particularly useful for unnamed code chunks.

file

Name of .RData file to export to. If not NULL, nothing will be returned to the main session (corresponding to export("none")).

Details

Under the hood, this function merely rm() variables that does not match value. Because job::job() returns everything at the end of the script, this defines what is returned.

Value

NULL invisibly.

Author(s)

Jonas Kristoffer Lindeløv, jonas@lindeloev.dk

Examples

if (rstudioapi::isAvailable()) {
  a = 55
  b = 77
  d = 88
  job::job({n = 11; a = 55; job::export("all")})  # export a, b, d, n
  job::job({n = 11; a = 11; job::export("changed")})  # export a, n
  job::job({n = 11; a = 11; job::export("new")})  # export n
  job::job({n = 11; a = 55; job::export(c(a, d, b))})  # export a, d, b
  job::job({n = 11; a = 55; job::export("none")})  # export nothing

  # To file
  job::job({n = 11; a = 11; job::export("changed", file = "jobresult.RData")})  # save a, n
  jobresult = new.env()  # import to this env instead of global
  load("jobresult.RData", envir = jobresult)
  print(jobresult$n)
}

lindeloev/job documentation built on Oct. 3, 2024, 4:45 a.m.