tests/utils/capture.r

# adapted from answers on https://stackoverflow.com/questions/4948361/how-do-i-save-warnings-and-errors-as-output-from-a-function
capture <- function(expr) {
  wrn <- err <- NULL
  value <- withCallingHandlers(tryCatch(expr,
                                        error=function(e) {
                                          err <<- e
                                          NULL
                                        }),
                                        warning=function(w) {
                                          wrn <<- append(wrn, conditionMessage(w))
                                          invokeRestart("muffleWarning")
                                        })
  list(value=value, warning=wrn, error=err$message)
}
KKPMW/matrixTests documentation built on Oct. 13, 2023, 2:08 p.m.