I have the following function:
fun = function(expr) {
mc = match.call()
env = as.environment(within(
list(),
expr = eval(mc$expr)
))
return(env)
}
which is called internally tryCatch(), so that any error conditions in are exprhandled gracefully.
It works fine with the standard error condition:
tryCatch({
fun({
stop('error')
})
}, error = function(e) {
message('error happened')
})
However, it does not display wait errors testthat(which is preferable for my particular use case):
library(testthat)
tryCatch({
fun({
expect_true(FALSE)
})
}, error = function(e) {
message('expectation not met')
})
or more simply:
library(testthat)
tryCatch({
expect_true(FALSE)
}, error = function(e) {
message('expectation not met')
})
The wait error is not caught.
This problem arose after the upgrade from R 3.2.2 to R 3.3.0 - that is, wait errors were caught only smoothly in R 3.2.2.
Is there a way to make expectations testthatexpected tryCatch()in R 3.3.0?
source
share