Skip to contents

When attributes are missing, the base::attr() function returns NULL. In those cases this function can be used to find an alternative value in one expression: attr(x,"dim") %otherwise% length(x)

Usage

a %otherwise% b

Arguments

a

value to check for NULL

b

value to substitute

Value

a, or b if a is NULL

Examples

x <- numeric(10)
l <- dim(x) %otherwise% c(length(x),1)
## example with attributes:
attr(x,"logLikelihood") <- logLikelihood(x)
#> Error in logLikelihood(x): could not find function "logLikelihood"
## elsewhere:
logLF <- attr(x,"logLikelihood") %otherwise% -Inf