Description Usage Arguments Value Examples
This function creates a fork,
sets the variable named targetValue
in the targetEnvironment
to NULL,
evaluates a segment of code evaluated in the fork,
and the result of the fork returned in a variable named targetValue
in the targetEnvironment
after the next top-level command completes.
If there is an error in the code, the returned variable will be a try-error
.
These effects are accomplished via the automatic creation and destruction of a taskCallback and other functions inside the mcparallelDoManager.
If job results have to be collected before you return to the top level, use mcparallelDoCheck.
1 2 | mcparallelDo(code, targetValue, verbose = TRUE,
targetEnvironment = .GlobalEnv)
|
code |
The code to evaluate within a fork wrapped in |
targetValue |
A character element indicating the variable that the result of that job should be assigned to targetEnvironment |
verbose |
A boolean element; if TRUE the completion of the fork expr will be accompanied by a message |
targetEnvironment |
The environment in which you want targetValue to be created |
The variable name of the job, this can be manually collected via mccollect or, if on Windows, an empty string
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## Create data
data(ToothGrowth)
## Trigger mcparallelDo to perform analysis on a fork
mcparallelDo({glm(len ~ supp * dose, data=ToothGrowth)},"interactionPredictorModel")
## Do other things
binaryPredictorModel <- glm(len ~ supp, data=ToothGrowth)
gaussianPredictorModel <- glm(len ~ dose, data=ToothGrowth)
## The result from mcparallelDo returns in your targetEnvironment,
## e.g. .GlobalEnv, when it is complete with a message (by default)
summary(interactionPredictorModel)
# Example of not returning a value until we return to the top level
for (i in 1:10) {
if (i == 1) {
mcparallelDo({2+2}, targetValue = "output")
}
if (exists("output")) print(i)
}
# Example of getting a value without returning to the top level
for (i in 1:10) {
if (i == 1) {
mcparallelDo({2+2}, targetValue = "output")
}
mcparallelDoCheck()
if (exists("output")) print(i)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.