assert_values {assertable}R Documentation

Assert that a data.frame's columns are non-NA/infinite, or are greater, less than, equal/not-equal, or contain specified values.


Given a data.frame or data.table object, make assertions about values of the columns within the object. Assert that a column contains no missing/infinite values, or that it is greater/less than, equal to, or contains either a single value, vector with nrow(data) values, or a vector of any length(for in option).


assert_values(data, colnames, test = "not_na", test_val = NA,
  display_rows = TRUE, na.rm = FALSE, warn_only = FALSE,
  quiet = FALSE)



A data.frame or data.table


Character vector with column names corresponding to columns in data


The type of evaluation you want to assert in your data

  • not_na: All values must not be Na

  • not_nan: All values must not be NaN

  • not_inf: All values must not be infinite

  • lt: All values must be less than test_val

  • lte: All values must be less than or equal to test_val

  • gt: All values must be greater than test_val

  • gte: All values must be greater than or equal to test_val

  • equal: All values must be equal to test_val

  • not_equal: All values must not equal test_val

  • in: All values must be one of the values in test_val


A single value, a vector with length = nrow(data), or a vector of any length (if using the in option for test. Must match the character type of colnames.


Do you want to show the actual rows that violate the assertion? Default=T


Do you want to remove NA and NaN values from assertions? Default=F


Do you want to warn, rather than error? Will return all offending rows from the first violation of the assertion Default=F


Do you want to suppress the printed messages when a test is passed? Default = F.


Throws error if test is violated. If warn_only=T, will return all offending rows from the first violation of the assertion.


assert_values(CO2, colnames="uptake", test="gt", 0) # Are all values greater than 0?
assert_values(CO2, colnames="conc", test="lte", 1000) # Are all values less than/equal to 1000?
## Not run: 
 assert_values(CO2, colnames="uptake", test="lt", 40) # Are all values less than 40?
 # Fails: not all values < 40.

## End(Not run)
assert_values(CO2, colnames="Treatment", test="in", test_val = c("nonchilled","chilled"))
CO2_mult <- CO2
CO2_mult$new_uptake <- CO2_mult$uptake * 2
assert_values(CO2, colnames="uptake", test="equal", CO2_mult$new_uptake/2)
## Not run: 
 assert_values(CO2, colnames="uptake", test="gt", CO2_mult$new_uptake/2, display_rows=F)
 # Fails: uptake !> new_uptake/2

## End(Not run)

[Package assertable version 0.2.8 Index]