Description Usage Arguments Value Examples
View source: R/assert_values.R
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).
1 2 3 |
data |
A data.frame or data.table |
colnames |
Character vector with column names corresponding to columns in data |
test |
The type of evaluation you want to assert in your data
|
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. |
display_rows |
Do you want to show the actual rows that violate the assertion? Default=T |
na.rm |
Do you want to remove NA and NaN values from assertions? Default=F |
warn_only |
Do you want to warn, rather than error? Will return all offending rows from the first violation of the assertion Default=F |
quiet |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.