% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/makeAssertion.R
\name{makeAssertion}
\alias{makeAssertion}
\alias{makeAssertionFunction}
\title{Turn a Check into an Assertion}
\usage{
makeAssertion(x, res, var.name, collection)

makeAssertionFunction(
  check.fun,
  c.fun = NULL,
  use.namespace = TRUE,
  coerce = FALSE,
  env = parent.frame()
)
}
\arguments{
\item{x}{[any]\cr
Object to check.}

\item{res}{[\code{TRUE} | \code{character(1)}]\cr
The result of a check function: \code{TRUE} for successful checks,
and an error message as string otherwise.}

\item{var.name}{[\code{character(1)}]\cr
The custom name for \code{x} as passed to any \code{assert*} function.
Defaults to a heuristic name lookup.}

\item{collection}{[\code{\link{AssertCollection}}]\cr
If an \code{\link{AssertCollection}} is provided, the error message is stored
in it. If \code{NULL}, an exception is raised if \code{res} is not
\code{TRUE}.}

\item{check.fun}{[\code{function}]\cr
Function which checks the input. Must return \code{TRUE} on success and a string with the error message otherwise.}

\item{c.fun}{[\code{character(1)}]\cr
If not \code{NULL}, instead of calling the function \code{check.fun}, use \code{.Call} to call a C function \dQuote{c.fun} with the identical
set of parameters. The C function must be registered as a native symbol, see \code{\link[base]{.Call}}.
Useful if \code{check.fun} is just a simple wrapper.}

\item{use.namespace}{[\code{logical(1)}]\cr
Call functions of \pkg{checkmate} using its namespace explicitly.
Can be set to \code{FALSE} so save some microseconds, but the checkmate package needs to be imported.
Default is \code{TRUE}.}

\item{coerce}{[\code{logical(1)}]\cr
If \code{TRUE}, injects some lines of code to convert numeric values to integer after an successful assertion.
Currently used in \code{\link{assertCount}}, \code{\link{assertInt}} and \code{\link{assertIntegerish}}.}

\item{env}{[\code{environment}]\cr
The environment of the created function. Default is the \code{\link[base]{parent.frame}}.}
}
\value{
\code{makeAssertion} invisibly returns the checked object if the check was successful,
 and an exception is raised (or its message stored in the collection) otherwise.
 \code{makeAssertionFunction} returns a \code{function}.
}
\description{
\code{makeAssertion} is the internal function used to evaluate the result of a
check and throw an exception if necessary.
\code{makeAssertionFunction} can be used to automatically create an assertion
function based on a check function (see example).
}
\examples{
# 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)
}
\seealso{
Other CustomConstructors: 
\code{\link{makeExpectation}()},
\code{\link{makeTest}()}
}
\concept{CustomConstructors}
