Evaluate an expression 'everywhere' on all connected daemons for the specified compute profile. Designed for performing setup operations across daemons or exporting common data, resultant changes to the global environment, loaded packages or options are persisted regardless of a daemon's 'cleanup' setting.

everywhere(.expr, ..., .args = list(), .compute = "default")

Arguments

.expr

an expression to evaluate asynchronously (of arbitrary length, wrapped in { } where necessary), or else a pre-constructed language object.

...

(optional) either named arguments (name = value pairs) specifying objects referenced, but not defined, in '.expr', or an environment containing such objects. See 'evaluation' section below.

.args

(optional) either a named list specifying objects referenced, but not defined, in '.expr', or an environment containing such objects. These objects will remain local to the evaluation environment as opposed to those supplied in '...' above - see 'evaluation' section below.

.compute

[default 'default'] character value for the compute profile to use (each compute profile has its own independent set of daemons).

Value

Invisible NULL.

Evaluation

The expression '.expr' will be evaluated in a separate R process in a clean environment (not the global environment), consisting only of the objects in the list or environment supplied to '.args', with the named objects passed as '...' (from the environment if one was supplied) assigned to the global environment of that process.

For evaluation to occur 'as if' in your global environment, supply objects to '...' rather than '.args'. For stricter scoping, use '.args', which limits where variables not explicitly passed as arguments to functions are found.

As evaluation occurs in a clean environment, all undefined objects must be supplied though '...' and/or '.args', including self-defined functions. Functions from a package should use namespaced calls such as mirai::mirai(), or else the package should be loaded beforehand in '.expr'.

Examples

if (interactive()) {
# Only run examples in interactive R sessions

daemons(1)
# export common data by a super-assignment expression:
everywhere(y <<- 3)
# '...' variables are assigned to the global environment:
everywhere({}, a = 1, b = 2)
m <- mirai(a + b - y == 0L)
call_mirai(m)$data
daemons(0)

daemons(1, dispatcher = FALSE)
everywhere(library(parallel))
m <- mirai("package:parallel" %in% search())
call_mirai(m)$data
daemons(0)

}