| Title: | A Simplified Interface for Running Commands on Parallel Processes |
|---|---|
| Description: | Provides a function that wraps mcparallel() and mccollect() from 'parallel' with temporary variables and a task handler. Wrapped in this way the results of an mcparallel() call can be returned to the R session when the fork is complete without explicitly issuing a specific mccollect() to retrieve the value. Outside of top-level tasks, multiple mcparallel() jobs can be retrieved with a single call to mcparallelDoCheck(). |
| Authors: | Russell S. Pierce |
| Maintainer: | Russell S. Pierce <[email protected]> |
| License: | GPL-2 |
| Version: | 1.0.1 |
| Built: | 2026-06-01 07:04:41 UTC |
| Source: | https://github.com/russellpierce/mcparalleldo |
A repository for a variety of useful functions.
The primary function of this package is mcparallelDo(). To use mcparallelDo(), simply invoke the function with a curly braced wrapped code and the character element name to which you want to assign the results.
checkIfJobStillRunning
checkIfJobStillRunning(targetJob, targetValue, verbose, targetEnvironment)checkIfJobStillRunning(targetJob, targetValue, verbose, targetEnvironment)
targetJob |
(character) The job name |
targetValue |
(character) The return variable name |
verbose |
(logical) Whether a message will be generated when complete |
targetEnvironment |
(environment) Target environment |
logical; TRUE if still running; FALSE if not running
Creates a callback handler function that can be added via addTaskCallback(). These functions run at the end of each completed R statement. This particular handler watches for the completion of the target job, which is created via mcparallel()
jobCompleteSelfDestructingHandler(targetJob, targetValue, verbose, targetEnvironment)jobCompleteSelfDestructingHandler(targetJob, targetValue, verbose, targetEnvironment)
targetJob |
(character) Name of the mcparallel job variable that is waiting for a result |
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 |
callback handler function
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.
mcparallelDo(code, targetValue, verbose = TRUE, targetEnvironment = .GlobalEnv)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
## 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) }## 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) }
Forces a check on all mcparallelDo() jobs and returns their values to the target environment if they are complete.
mcparallelDoCheck()mcparallelDoCheck()
A named logical vector, TRUE if complete, FALSE if not complete, and an empty logical vector if on Windows
The mcparallelDoManager Class and Object
mcparallelDoManagerClassmcparallelDoManagerClass
Class 'R6ClassGenerator' <mcparallelDoManager> object generator
Public:
h: list
runningJobs: list
addJob: function (jobName, targetValue, verbose, targetEnvironment)
removeJob: function (x)
checkJobs: function ()
clone: function (deep = FALSE)
Parent env: <environment: namespace:mcparallelDo>
Locked objects: TRUE
Locked class: FALSE
Portable: TRUE
- attr(*, "name")= chr "mcparallelDoManager_generator"