future (version 1.2.0)

eager: Create a uniprocess future whose value will be in the current R session

Description

A uniprocess future is a future that is evaluated sequentially in the current R session. The default is to resolve it eagerly, which means that its value is computed and resolved immediately, which is how regular expressions are evaluated in R. The only difference to R itself is that globals are validated by default just as for all other types of futures in this package.

Usage

eager(expr, envir = parent.frame(), substitute = TRUE, globals = TRUE, local = TRUE, earlySignal = FALSE, label = NULL, lazy = FALSE, ...)
transparent(expr, envir = parent.frame(), substitute = TRUE, globals = FALSE, local = FALSE, earlySignal = TRUE, label = NULL, lazy = FALSE, ...)
lazy(expr, envir = parent.frame(), substitute = TRUE, globals = TRUE, local = TRUE, earlySignal = FALSE, label = NULL, lazy = TRUE, ...)

Arguments

expr
envir
The environment from where global objects should be identified. Depending on "evaluator", it may also be the environment in which the expression is evaluated.
substitute
If TRUE, argument expr is substitute():ed, otherwise not.
globals
A logical, a character vector, or a named list for controlling how globals are handled. For details, see below section. This argument can be specified via the ... arguments for future() and futureCall().
local
If TRUE, the expression is evaluated such that all assignments are done to local temporary environment, otherwise the assignments are done in the calling environment.
earlySignal
Specified whether conditions should be signaled as soon as possible or not.
label
An optional character string label attached to the future.
lazy
If FALSE (default), the future is resolved eagerly (immediately), otherwise not.
...
Additional arguments passed to the "evaluator".

Value

A UniprocessFuture.

transparent futures

Transparent futures are eager uniprocess futures configured to emulate how R evaluates expressions as far as possible. For instance, errors and warnings are signaled immediately and assignments are done to the calling environment (without local() as default for all other types of futures). This makes transparent futures ideal for troubleshooting, especially when there are errors.

Details

The preferred way to create a uniprocess future is not to call these functions directly, but to register them via plan(eager) such that it becomes the default mechanism for all futures. After this future() and %<-% will create eager uniprocess futures.

Examples

Run this code
## Use an eager uniprocess futures
plan(eager)

## A global variable
a <- 0

## Create an eager uniprocess future (explicitly)
f <- future({
  b <- 3
  c <- 2
  a * b * c
})

## Since 'a' is a global variable in future 'f' which
## is eagerly resolved (default), this global has already
## been resolved / incorporated, and any changes to 'a'
## at this point will _not_ affect the value of 'f'.
a <- 7
print(a)

v <- value(f)
print(v)
stopifnot(v == 0)

Run the code above in your browser using DataLab