R/try0_function.R

Defines functions try0

Documented in try0

#' Wrapper for try which returns second argument if not succesful
#' @param expr expression to be tested
#' @param ifError return value if test fails
#' @description Returns second argument if expression in first argument fails.
#' @author Kim Rand
#' @examples
#' try0(as.formula(list()))
#' try0(as.formula(a ~ b))
#' @export
try0 <- function(expr, ifError = NULL) {
  tr <- try(expr, TRUE)
  succ <- (class(tr) != "try-error")
  if(!succ) return(ifError)
  return(tr)
}
intelligentaccident/xreg documentation built on Jan. 17, 2021, 7:38 a.m.