Learn R Programming

pointblank (version 0.7.0)

stop_if_not: The next generation of stopifnot()-type functions: stop_if_not()

Description

This is stopifnot() but with a twist: it works well as a standalone, replacement for stopifnot() but is also customized for use in validation checks in R Markdown documents where pointblank is loaded. Using stop_if_not() in a code chunk where the validate = TRUE option is set will yield the correct reporting of successes and failures whereas stopifnot() does not.

Usage

stop_if_not(...)

Arguments

...

R expressions that should each evaluate to (a logical vector of all) TRUE.

Value

NULL if all statements in ... are TRUE.

Function ID

12-5

See Also

Other Utility and Helper Functions: affix_datetime(), affix_date(), col_schema(), from_github(), has_columns()

Examples

Run this code
# NOT RUN {
# This checks whether the number of
# rows in `small_table` is greater
# than `10`
stop_if_not(nrow(small_table) > 10)

# This will stop for sure: there
# isn't a `time` column in `small_table`
# (but there are the `date_time` and
# `date` columns)
# stop_if_not("time" %in% colnames(small_table))

# You're not bound to using tabular
# data here, any statements that
# evaluate to logical vectors will work
stop_if_not(1 < 20:25 - 18)

# }

Run the code above in your browser using DataLab