File: on_failure.Rd

package info (click to toggle)
r-cran-assertthat 0.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 220 kB
  • sloc: sh: 9; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 759 bytes parent folder | download | duplicates (3)
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
28
29
30
31
32
33
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/on-failure.r
\name{on_failure}
\alias{on_failure}
\alias{on_failure<-}
\title{Custom failure messages for assertions.}
\usage{
on_failure(x)

on_failure(x) <- value
}
\arguments{
\item{x}{a assertion function that returns \code{TRUE} if the assertion
is met, \code{FALSE} otherwise.}

\item{value}{a function with parameters \code{call} and \code{env}
that returns a custom error message as a string.}
}
\description{
Custom failure messages for assertions.
}
\examples{
is_odd <- function(x) {
  assert_that(is.numeric(x), length(x) == 1)
  x \%\% 2 == 1
}
see_if(is_odd(2))

on_failure(is_odd) <- function(call, env) {
  paste0(deparse(call$x), " is even")
}
see_if(is_odd(2))
}