future (version 1.0.1)

eager: Create an eager future whose value will be resolved immediately

Description

An eager future is a future that uses eager evaluation, 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, gc = FALSE, earlySignal = FALSE, ...)

Arguments

expr
envir
The environment in which the evaluation is done (or inherits from if local is TRUE).
substitute
If TRUE, argument expr is substitute():ed, otherwise not.
globals
If TRUE, global objects are validated at the point in time when the future is created (always before it is resolved), that is, they identified and located. If some globals fail to be located, an informative error is generated.
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.
gc
If TRUE, the garbage collector run after the future is resolved (in the process that evaluated the future).
earlySignal
Specified whether conditions should be signaled as soon as possible or not.
...
Not used.

Value

An EagerFuture.

transparent futures

Transparent futures are eager 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 an eager future is not to call this function directly, but to register it via plan(eager) such that it becomes the default mechanism for all futures. After this future() and %<=%< a=""> will create eager futures.

Examples

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

## A global variable
a <- 0

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

## Since 'a' is a global variable in _eager_ future 'f',
## it already has been resolved, 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