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)
}

Try the matrixTests package in your browser

Any scripts or data that you put into this service are public.

matrixTests documentation built on Oct. 6, 2023, 1:07 a.m.