Description Usage Arguments Details Value Examples
a single function that can do several different types of sanity checks at the same time
1 2 3 |
x |
an object to be checked., |
NULL_allowed |
whether a x == NULL is allowed, |
Class |
the correct class of x |
min_oberserv |
the min number of row / length that x should have, |
exact_in_match |
each element of x shall be found in the exact_in_match vector if exact_in_match is a data.frame, we will get the colnames of it as exact_in_match |
fuzzy_match |
TEST feature |
exact_length |
can let you test the exact length of a vector, OR exact number of colnames |
complete_cases |
TRUE or NULL # check whether a dataframe have NA values |
STOP |
whether to stop if there is an error. |
message_provided |
replace the default error message |
See sample code
return nothing if x passes checks, otherwise an error message
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ###_____ unit test ____
data = ggplot2::diamonds
# sanity_check(dasfdfdsfsgre)
null_checl = NULL ;
tryCatch( sanity_check(null_checl),
error = function(err) print(err))
tryCatch( sanity_check(null_checl,NULL_allowed = TRUE),
error = function(err) print(err))
tryCatch( sanity_check(c('x','y'),min_oberserv = 3),
error = function(err) print(err))
tryCatch( sanity_check(c('x','y'),min_oberserv = 2),
error = function(err) print(err))
tryCatch( sanity_check(data,Class = 'data.frame2'),
error = function(err) print(err))
tryCatch( sanity_check(data,min_oberserv = 3000000),
error = function(err) print(err))
tryCatch( sanity_check(data,exact_length = ncol(data) ),
error = function(err) print(err))
tryCatch( sanity_check(
data.frame(data,NA,stringsAsFactors = FALSE)[1:10,],
complete_cases = TRUE ),
error = function(err) print(err))
colnames(data)
tryCatch( sanity_check(x= c('carat') ,exact_in_match = data),
error = function(err) print(err))
tryCatch( sanity_check(x= c('carat') ,exact_in_match = colnames(data)) ,
error = function(err) print(err))
tryCatch( sanity_check(x= c('carat2') ,exact_in_match = data),
error = function(err) print(err))
tryCatch( sanity_check(x= c('carat','carat2') ,exact_in_match = data),
error = function(err) print(err))
tryCatch( sanity_check(x=colnames(data),exact_in_match = c('carat')),
error = function(err) print(err))
tryCatch( sanity_check(x=data,exact_in_match = c('carat2')),
error = function(err) print(err))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.