Apply R expressions in a parallel way
async_expr(
.X,
.expr,
.varname = "x",
envir = parent.frame(),
.pre_run = NULL,
.ncore = future::availableCores(),
...
)a list whose length equals to .X. The value of each item
returned depends on whether async is called. See details for workflow.
a vector or a list to apply evaluation on
R expression, unquoted
variable name representing element of each .X
environment to evaluate expressions
expressions to be evaluated before looping.
number of CPU cores
passed to future::future
async_expr uses lapply and future::future internally.
Within each loop, an item in ".X" will be assigned to variable "x"
(defined by ".varname") and enter the evaluation. During the evaluation,
function async is provided. Expressions within async will be
evaluated in another session, otherwise will be evaluated in current session.
Below is the workflow:
Run .pre_run
For i in seq_along(.X):
1. Assign x with .X[[i]], variable name x is
defined by .varname
2. Evaluate expr in current session.
a. If async is not called, return evaluated expr
b. If async(aync_expr) is called, evaluate aync_expr
in another session, and return the evaluation results if aync_expr