future (version 0.8.0)

plan: Plan how to resolve a future

Description

This function allows you to plan the future, more specifically, it specifies how future():s are resolved, e.g. by eager or by lazy evaluation.

Usage

plan(strategy = NULL, ..., substitute = TRUE, .call = TRUE)

Arguments

strategy
The evaluation function to use for resolving a future. If NULL, then the current strategy is returned.
...
Additional arguments overriding the default arguments of the evaluation function.
substitute
If TRUE, the strategy expression is substitute():d, otherwise not.
.call
(internal) Used to record the call to this function.

Value

  • If a new strategy is chosen, then the previous one is returned (invisible), otherwise the current one is returned (visibly).

Details

The default strategy is eager, which can be set by option future_plan and, if that is not set, system environment variable R_FUTURE_PLAN. To reset the strategy back to the default, use plan("default").

See Also

Evaluation functions provided by this package are eager(), lazy() and multicore(). Other package may provide additional evaluation strategies/functions.

Examples

Run this code
a <- b <- c <- NA_real_

# A lazy future (evaluated in a local environment)
plan(lazy)
f <- future({
  a <- 7
  b <- 3
  c <- 2
  a * b * c
})
y <- value(f)
print(y)
str(list(a=a, b=b, c=c)) ## All NAs


# An eager future (evaluated in a local environment)
plan(eager)
f <- future({
  a <- 7
  b <- 3
  c <- 2
  a * b * c
})
y <- value(f)
print(y)
str(list(a=a, b=b, c=c)) ## All NAs


# A multicore future evaluated in a local environment
plan(multicore)
f <- future({
  a <- 7
  b <- 3
  c <- 2
  a * b * c
})
y <- value(f)
print(y)
str(list(a=a, b=b, c=c)) ## All NAs


# An eager future evaluated in the global environment
plan(eager, local=FALSE)
f <- future({
  a <- 7
  b <- 3
  c <- 2
  a * b * c
})
y <- value(f)
print(y)
str(list(a=a, b=b, c=c)) ## Assigned the new values

Run the code above in your browser using DataLab