smoke_test {accumulate} | R Documentation |
Check your testing function against common edge cases
Description
Writing a testing function that works on any subset of records of a
dataframe can be quite subtle. This function tries the testing function on a
number of common (edge) cases that are easily overlooked. It is not
a unit test: a smoke test will not tell you whether your output is correct.
It only checks the output data type (must be TRUE
or FALSE
and
reports if errors, warnings, or messages occur.
Usage
smoke_test(dat, test, verbose = FALSE, halt = TRUE)
Arguments
dat |
an example dataset. For example the full dataset
to be fed into |
test |
A testing function to be passed as argument to |
verbose |
|
halt |
|
Value
NULL
, invisibly. This function has as side-effect that test
results are printed to screen.
Examples
dat <- data.frame(x = 1:5, y=(-2):2)
smoke_test(dat, function(d) y > 0) #error: Y not found
smoke_test(dat, function(d) d$y > 0) # issue: output too long, not robust against NA
smoke_test(dat, function(d) sum(d$y > 0) > 2) # issue: not robust against NA
smoke_test(dat, function(d) sum(d$y > 0, na.rm=TRUE) > 2) # OK