predicate <- within_bounds(3,4)
predicate(pi)
## is equivalent to
within_bounds(3,4)(pi)
# a correlation coefficient must always be between 0 and 1
coeff <- cor.test(c(1,2,3), c(.5, 2.4, 4))[["estimate"]]
within_bounds(0,1)(coeff)
## check for positive number
positivep <- within_bounds(0, Inf, include.lower=FALSE)
## this is meant to be used as a predicate in an assert statement
assert(mtcars, within_bounds(4,8), cyl)
## or in a pipeline
library(magrittr)
mtcars %>%
assert(within_bounds(4,8), cyl)
Run the code above in your browser using DataLab