insist {assertr}R Documentation

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


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.


  success_fun = success_continue,
  error_fun = error_stop,
  skip_chain_opts = FALSE,
  obligatory = FALSE,
  defect_fun = defect_append,
  description = NA



A data frame


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.


Function to call if assertion passes. Defaults to returning data.


Function to call if assertion fails. Defaults to printing a summary of all errors.


If TRUE, success_fun and error_fun are used even if assertion is called within a chain.


If TRUE and assertion failed the data is marked as defective. For defective data, all the following rules are handled by defect_fun function.


Function to call when data is defective. Defaults to skipping assertion and storing info about it in special attribute.


Custom description of the rule. Is stored in result reports and data.


For examples of possible choices for the success_fun and error_fun parameters, run help("success_and_error_functions")


By default, the data is returned if dynamically created predicate assertion is TRUE and and error is thrown if not. If a non-default success_fun or error_fun is used, the return values of these function will be returned.


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

See Also

assert verify insist_rows assert_rows


insist(iris, within_n_sds(3), Sepal.Length)   # returns iris


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)

[Package assertr version 3.0.1 Index]