sanity_check: check x with various characters

Description Usage Arguments Details Value Examples

View source: R/linear.tools.R

Description

a single function that can do several different types of sanity checks at the same time

Usage

1
2
3
sanity_check(x, NULL_allowed = FALSE, Class = NULL, min_oberserv = NULL,
  exact_in_match = NULL, fuzzy_match = NULL, exact_length = NULL,
  complete_cases = NULL, STOP = 1, message_provided = "")

Arguments

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

Details

See sample code

Value

return nothing if x passes checks, otherwise an error message

Examples

 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))

linear.tools documentation built on May 2, 2019, 3:17 a.m.