R/inspect_par_.R
inspect_par_bernoulli.Rd
inspect_par_bernoulli
checks if an object is an eligible
Bernoulli/Binomial proportion. This can be useful to validate inputs,
intermediate calculations or outputs in user-defined functions.
inspect_par_bernoulli(x)
x | An arbitrary object. |
---|
inspect_par_bernoulli
does not return any output. There are two
possible outcomes:
The call is silent if x
is an eligible Bernoulli/Binomial proportion.
An informative error message is thrown otherwise.
inspect_par_bernoulli
conducts a series of tests to check if x
is an eligible Bernoulli/Binomial proportion. Namely, inspect_par_bernoulli
checks if:
x
is NULL
or empty.
x
is an atomic vector
x
is numeric
x
has length
1
x
is NA
or NaN
.
x
is in the (0, 1) interval.
inspect_par_multinomial
to validate parameters for
the Multinomial distribution.
inspect_par_beta
to validate parameters for the
Beta distribution.
inspect_par_dirichlet
to validate parameters for
the Dirichlet distribution.
inspect_par_haldane
to validate parameters for the
Haldane distribution.
inspect_data_dichotomous
to validate dichotomous
data.
inspect_prob
to check if an object is a numeric
vector of valid probability values.
# Calls that pass silently:
x <- 0.5
inspect_par_bernoulli(x)
inspect_par_bernoulli(0.1)
# Calls that throw an informative error message:
mylist <- list(
NULL, TRUE, factor(.5), matrix(0.5), "0.5",
list(0.5), NA, NaN, numeric(0), c(0.1, 0.5), -0.5, 1.1
)
try(inspect_par_bernoulli(mylist[[1]]))
#> Error in inspect_par_bernoulli(mylist[[1]]) :
#> Invalid argument: mylist[[1]] is NULL.
try(inspect_par_bernoulli(mylist[[2]]))
#> Error in inspect_par_bernoulli(mylist[[2]]) :
#> Invalid argument: mylist[[2]] must be numeric.
try(inspect_par_bernoulli(mylist[[3]]))
#> Error in inspect_par_bernoulli(mylist[[3]]) :
#> Invalid argument: mylist[[3]] must be an atomic vector.
try(inspect_par_bernoulli(mylist[[4]]))
#> Error in inspect_par_bernoulli(mylist[[4]]) :
#> Invalid argument: mylist[[4]] must be an atomic vector.
try(inspect_par_bernoulli(mylist[[5]]))
#> Error in inspect_par_bernoulli(mylist[[5]]) :
#> Invalid argument: mylist[[5]] must be numeric.
try(inspect_par_bernoulli(mylist[[6]]))
#> Error in inspect_par_bernoulli(mylist[[6]]) :
#> Invalid argument: mylist[[6]] must be an atomic vector.
try(inspect_par_bernoulli(mylist[[7]]))
#> Error in inspect_par_bernoulli(mylist[[7]]) :
#> Invalid argument: mylist[[7]] is NA or NaN.
try(inspect_par_bernoulli(mylist[[8]]))
#> Error in inspect_par_bernoulli(mylist[[8]]) :
#> Invalid argument: mylist[[8]] is NA or NaN.
try(inspect_par_bernoulli(mylist[[9]]))
#> Error in inspect_par_bernoulli(mylist[[9]]) :
#> Invalid argument: mylist[[9]] must be of length 1.
try(inspect_par_bernoulli(mylist[[10]]))
#> Error in inspect_par_bernoulli(mylist[[10]]) :
#> Invalid argument: mylist[[10]] must be of length 1.
try(inspect_par_bernoulli(mylist[[11]]))
#> Error in inspect_par_bernoulli(mylist[[11]]) :
#> Invalid argument: mylist[[11]] must be in the (0, 1) interval.
try(inspect_par_bernoulli(mylist[[12]]))
#> Error in inspect_par_bernoulli(mylist[[12]]) :
#> Invalid argument: mylist[[12]] must be in the (0, 1) interval.