future()
:s are resolved,
e.g. sequentially or in parallel.
plan(strategy = NULL, ..., substitute = TRUE, .call = TRUE)
strategy
expression is
substitute()
:d, otherwise not.eager
:
Resolves futures sequentially in the current R process. lazy
:
Resolves futures synchronously (sequentially) in the current
R process, but only if their values are requested. Futures for
which the values are never requested will not be evaluated. transparent
:
Resolves futures synchronously (sequentially) in the current
R process and assignments will be done to the calling environment.
Early stopping is enabled by default. multisession
:
Resolves futures asynchronously (in parallel) in separate
R sessions running in the background on the same machine. multicore
:
Resolves futures asynchronously (in parallel) in separate
forked R processes running in the background on
the same machine. Not supported on Windows. multiprocess
:
If multicore evaluation is supported, that will be used, cluster
:
Resolves futures asynchronously (in parallel) in separate
R sessions running typically on one or more machines. remote
:
Resolves futures asynchronously in a separate R session
running on a separate machine, typically on a different
network. eager
, but the default can be
configured 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")
.
a <- b <- c <- NA_real_
# A lazy future
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
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
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
## Multisession futures gives an error on R CMD check on
## Windows (but not Linux or OS X) for unknown reasons.
## The same code works in package tests.
# A multisession future
plan(multisession)
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
Run the code above in your browser using DataLab