inspect_log_base
checks if an object is a valid a logarithmic
base. This can be useful to validate inputs in user-defined functions.
inspect_log_base(x)
x | An arbitrary object. |
---|
inspect_log_base
does not return any output. There are two possible
outcomes:
The call is silent if x
is a numeric vector of length
1 that is a valid logarithmic base.
An informative error message is thrown otherwise.
inspect_log_base
conducts a series of tests to check if x
is a
valid logarithmic base. Namely, inspect_log_base
checks if:
x
is NULL
or empty.
x
is an atomic vector of length
1.
x
is numeric.
x
is NA
or NaN
.
x
is positive.
bfactor_log_interpret
for the interpretation of the
logarithms of Bayes factors.
inspect_bfactor_log
to check if an object is a
numeric vector of valid logarithmic Bayes factor values.
# Calls that pass silently:
x1 <- 10
x2 <- exp(1)
x3 <- 0.5
inspect_log_base(x1)
inspect_log_base(x2)
inspect_log_base(x3)
# Calls that throw informative error messages:
mylist <- list(
NULL, numeric(0), TRUE, factor(10),
list(10), matrix(10), NaN, NA, -1, 0
)
try(inspect_log_base(mylist[[1]]))
#> Error in inspect_log_base(mylist[[1]]) :
#> Invalid argument: mylist[[1]] is NULL.
try(inspect_log_base(mylist[[2]]))
#> Error in inspect_log_base(mylist[[2]]) :
#> Invalid argument: mylist[[2]] must be an atomic vector of length 1.
try(inspect_log_base(mylist[[3]]))
#> Error in inspect_log_base(mylist[[3]]) :
#> Invalid argument: the type of mylist[[3]] must be numeric.
try(inspect_log_base(mylist[[4]]))
#> Error in inspect_log_base(mylist[[4]]) :
#> Invalid argument: mylist[[4]] must be an atomic vector of length 1.
try(inspect_log_base(mylist[[5]]))
#> Error in inspect_log_base(mylist[[5]]) :
#> Invalid argument: mylist[[5]] must be an atomic vector of length 1.
try(inspect_log_base(mylist[[6]]))
#> Error in inspect_log_base(mylist[[6]]) :
#> Invalid argument: mylist[[6]] must be an atomic vector of length 1.
try(inspect_log_base(mylist[[7]]))
#> Error in inspect_log_base(mylist[[7]]) :
#> Invalid argument: mylist[[7]] is NA or NaN.
try(inspect_log_base(mylist[[8]]))
#> Error in inspect_log_base(mylist[[8]]) :
#> Invalid argument: mylist[[8]] is NA or NaN.
try(inspect_log_base(mylist[[9]]))
#> Error in inspect_log_base(mylist[[9]]) :
#> Invalid argument: mylist[[9]] must be positive.
try(inspect_log_base(mylist[[10]]))
#> Error in inspect_log_base(mylist[[10]]) :
#> Invalid argument: mylist[[10]] must be positive.