Learn R Programming

inspector (version 1.0.3)

inspect_log_base: Validate logarithmic bases

Description

inspect_log_base checks if an object is a valid a logarithmic base. This can be useful to validate inputs in user-defined functions.

Usage

inspect_log_base(x)

Arguments

x

An arbitrary object.

Value

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.

Details

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.

See Also

Examples

Run this code
# NOT RUN {
# 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]]))
try(inspect_log_base(mylist[[2]]))
try(inspect_log_base(mylist[[3]]))
try(inspect_log_base(mylist[[4]]))
try(inspect_log_base(mylist[[5]]))
try(inspect_log_base(mylist[[6]]))
try(inspect_log_base(mylist[[7]]))
try(inspect_log_base(mylist[[8]]))
try(inspect_log_base(mylist[[9]]))
try(inspect_log_base(mylist[[10]]))
# }

Run the code above in your browser using DataLab