Skip to content
Permalink
Browse files

Switch to checkmate

  • Loading branch information
nutterb committed Feb 26, 2016
1 parent dde1d21 commit 59969b73dcace8de42780e802637e37437347b4d
@@ -18,5 +18,5 @@ Suggests:
RoxygenNote: 5.0.1
Imports: parallel,
R.utils,
ArgumentCheck,
checkmate (>= 1.6.3),
R6
@@ -1,8 +1,10 @@
# Generated by roxygen2: do not edit by hand
# Generated by roxygen2 (4.1.1): do not edit by hand

export(mcparallelDo)
export(mcparallelDoCheck)
importFrom(ArgumentCheck,addError)
importFrom(ArgumentCheck,finishArgCheck)
importFrom(R.utils,tempvar)
importFrom(R6,R6Class)
importFrom(checkmate,assertCharacter)
importFrom(checkmate,assertEnvironment)
importFrom(checkmate,makeAssertCollection)
importFrom(checkmate,reportAssertions)
@@ -155,30 +155,23 @@ NULL
#' mcparallelDoCheck()
#' if (exists("output")) print(i)
#' }
#' @importFrom ArgumentCheck addError finishArgCheck
#' @importFrom checkmate assertCharacter makeAssertCollection assertEnvironment reportAssertions
#' @importFrom R.utils tempvar
#' @export
mcparallelDo <- function(code, targetValue, verbose = TRUE, targetEnvironment = .GlobalEnv) {
Check <- ArgumentCheck::newArgCheck()
if (!is.character(targetValue)) {
ArgumentCheck::addError(
msg = "targetValue must be a character",
argcheck = Check
)
}
coll <- checkmate::makeAssertCollection()

checkmate::assertCharacter(targetValue,
add = coll)

if (length(targetValue) != 1) {
ArgumentCheck::addError(
msg = "targetValue must be a single element",
argcheck = Check
)
coll$push("targetValue must be a single element")
}
if (!is.environment(targetEnvironment)) {
ArgumentCheck::addError(
msg = "targetEnvironment must be an environment",
argcheck = Check
)
}
ArgumentCheck::finishArgCheck(Check)

checkmate::assertEnvironment(targetEnvironment,
add = coll)

checkmate::reportAssertions(coll)

# Special handling for Windows
if (!.Platform$OS.type=="unix") {
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/mcparallelDo.R
\name{checkIfJobStillRunning}
\alias{checkIfJobStillRunning}
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/mcparallelDo.R
\name{jobCompleteSelfDestructingHandler}
\alias{jobCompleteSelfDestructingHandler}
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/mcparallelDo.R
\docType{package}
\name{mcparallelDo-package}
@@ -8,7 +8,7 @@
A repository for a variety of useful functions.
}
\details{
The primary function of this package is mcparallelDo().
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.
}

@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/mcparallelDo.R
\name{mcparallelDo}
\alias{mcparallelDo}
@@ -20,9 +20,9 @@ mcparallelDo(code, targetValue, verbose = TRUE,
The variable name of the job, this can be manually collected via mccollect or, if on Windows, an empty string
}
\description{
This function creates a fork,
This function creates a fork,
sets the variable named \code{targetValue} in the \code{targetEnvironment} to NULL,
evaluates a segment of code evaluated in the fork,
evaluates a segment of code evaluated in the fork,
and the result of the fork returned in a variable named \code{targetValue} in the \code{targetEnvironment} after the next top-level command completes.
If there is an error in the code, the returned variable will be a \code{try-error}.
These effects are accomplished via the automatic creation and destruction of a taskCallback and other functions inside the mcparallelDoManager.
@@ -36,7 +36,7 @@ mcparallelDo({glm(len ~ supp * dose, data=ToothGrowth)},"interactionPredictorMod
## Do other things
binaryPredictorModel <- glm(len ~ supp, data=ToothGrowth)
gaussianPredictorModel <- glm(len ~ dose, data=ToothGrowth)
## The result from mcparallelDo returns in your targetEnvironment,
## The result from mcparallelDo returns in your targetEnvironment,
## e.g. .GlobalEnv, when it is complete with a message (by default)
summary(interactionPredictorModel)

@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/mcparallelDo.R
\name{mcparallelDoCheck}
\alias{mcparallelDoCheck}
@@ -1,11 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/mcparallelDo.R
\docType{class}
\name{mcparallelDoManagerClass}
\alias{mcparallelDoManager}
\alias{mcparallelDoManagerClass}
\title{The mcparallelDoManager Class and Object}
\format{An object of class \code{R6ClassGenerator} of length 24.}
\format{\preformatted{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"
}}
\usage{
mcparallelDoManagerClass
}

0 comments on commit 59969b7

Please sign in to comment.
You can’t perform that action at this time.