Learn R Programming

doRedis (version 3.0.2)

setExport: Manually add symbol names to the worker environment export list.

Description

The setExport function lets users manually declare symbol names of corresponding objects that should be exported to workers.

Usage

setExport(names = c())

Value

The value of names is invisibly returned (this function is used ofr its side effect).

Arguments

names

A character vector of symbol names to export.

Details

The foreach function includes a similar .export parameter.

We provide this supplemental export option for users without direct access to the foreach function, for example, when foreach is used inside another package.

Examples

Run this code
if (FALSE) {
registerDoRedis("work queue")
startLocalWorkers(n=1, queue="work queue", linger=1)

f <- function() pi

(foreach(1) %dopar% tryCatch(eval(call("f")), error = as.character))
# Returns the error converted to a message:
# Error in eval(call("f")) : task 1 failed - could not find function "f"

# Manually export the symbol f:
setExport("f")
(foreach(1) %dopar% eval(call("f")))
# Now f is found.

removeQueue("work queue")
}

Run the code above in your browser using DataLab