assert <- function(p) {
predicate_name <- deparse(
substitute(p)
)
function(x) {
object_name <- deparse(
substitute(x)
)
error_message <- paste0(
"Assertion failed. The predicate ",
"'", predicate_name, "'",
" returned FALSE with input ",
"'", object_name, "'", "."
)
if (isTRUE(p(x))) {
invisible(x)
} else {
stop(
error_message,
call. = FALSE
)
}
}
}
and <- function(...) {
function(x) {
reduce(
fn = function(acc, p) {
acc && p(x)
},
init = TRUE
)(x = list(...))
}
}
or <- function(...) {
function(x) {
reduce(
fn = function(acc, p) {
acc || p(x)
},
init = FALSE
)(x = list(...))
}
}
not <- function(p) {
function(x) {
!p(x)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.