smoke_test | R Documentation |
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.
smoke_test(dat, test, verbose = FALSE, halt = TRUE)
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 |
|
NULL
, invisibly. This function has as side-effect that test
results are printed to screen.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.