View source: R/makeAssertion.R
makeAssertion | R Documentation |
makeAssertion
is the internal function used to evaluate the result of a
check and throw an exception if necessary.
makeAssertionFunction
can be used to automatically create an assertion
function based on a check function (see example).
makeAssertion(x, res, var.name, collection)
makeAssertionFunction(
check.fun,
c.fun = NULL,
use.namespace = TRUE,
coerce = FALSE,
env = parent.frame()
)
x |
[any] |
res |
[ |
var.name |
[ |
collection |
[ |
check.fun |
[ |
c.fun |
[ |
use.namespace |
[ |
coerce |
[ |
env |
[ |
makeAssertion
invisibly returns the checked object if the check was successful,
and an exception is raised (or its message stored in the collection) otherwise.
makeAssertionFunction
returns a function
.
Other CustomConstructors:
makeExpectation()
,
makeTest()
# Simple custom check function
checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE
# Create the respective assert function
assertFalse = function(x, .var.name = vname(x), add = NULL) {
res = checkFalse(x)
makeAssertion(x, res, .var.name, add)
}
# Alternative: Automatically create such a function
assertFalse = makeAssertionFunction(checkFalse)
print(assertFalse)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.