Raises error if dynamically created predicate is FALSE in any columns selected

Description

Meant for use in a data analysis pipeline, this function applies a predicate generating function to each of the columns indicated. It will then use these predicates to check every element of those columns. If any of these predicate applications yield FALSE, this function will raise an error, effectively terminating the pipeline early. If there are no FALSES, this function will just return the data that it was supplied for further use in later parts of the pipeline.

Usage

1
2
3
4
insist(data, predicate_generator, ..., error_fun = assertr_stop)

insist_(data, predicate_generator, ..., .dots, error_fun = assertr_stop,
  .nameofpred = "")

Arguments

data

A data frame

predicate_generator

A function that is applied to each of the column vectors selected. This will produce, for every column, a true predicate function to be applied to every element in the column vectors selected

...

Comma separated list of unquoted expressions. Uses dplyr's select to select columns from data.

error_fun

Function to call if assertion fails. Takes one error string. Uses stop by default

.dots

Use insist_() to select columns using standard evaluation.

.nameofpred

Text representation of predicate for printing in case of assertion violation. Will automatically be retrieved if left blank (default)

Value

data if dynamically created predicate assertion is TRUE. error if not.

Note

See vignette("assertr") for how to use this in context

See Also

assert verify insist_rows assert_rows

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
insist(iris, within_n_sds(3), Sepal.Length)   # returns iris

# equivalent using standard evaluation
insist_(iris, within_n_sds(3), "Sepal.Length")

library(magrittr)

iris %>%
  insist(within_n_sds(4), Sepal.Length:Petal.Width)
  # anything here will run

## Not run: 
iris %>%
  insist(within_n_sds(3), Sepal.Length:Petal.Width)
  # datum at index 16 of 'Sepal.Width' vector is (4.4)
  # is outside 3 standard deviations from the mean of Sepal.Width.
  # The check fails, raises a fatal error, and the pipeline
  # is terminated so nothing after this statement will run
## End(Not run)