Closed
Description
(This is softly mentioned #614, and related to it since I'm trying to replace info
functionality.)
I want to test for silence (or warning or error) from a function and still test its output. If a function is "expensive", I'd much rather not run it multiple times. However, the current expect_silent
and family explicitly discard the object upon execution.
Right now I can do
expect_silent2 <- function(obj) { expect_silent(o <- obj) ; o ; }
but this does not work using the NSE hack for replacing info
. That is:
expect_silent(myfunc(FALSE))
expect_silent(myfunc(TRUE))
# Error: myfunc(TRUE) produced warnings.
expect_silent2(myfunc(FALSE))
# [1] FALSE
expect_silent2(myfunc(TRUE))
# Error: o <- obj produced warnings.
That last error message isn't very useful, so I try the NSE trick:
expect_silent3 <- function(obj) { eval(bquote(expect_silent(.(o <- obj)))) ; o ; }
expect_silent3(myfunc(TRUE))
# Warning in myfunc(TRUE) : quux
# [1] TRUE
expect_silent4 <- function(obj) { eval(bquote(expect_silent(o <- .(obj)))) ; o ; }
expect_silent4(myfunc(TRUE))
# Warning in myfunc(TRUE) : quux
# [1] TRUE
expect_silent5 <- function(obj) eval(bquote(expect_silent2(.(obj))))
expect_silent5(myfunc(TRUE))
# Warning in myfunc(TRUE) : quux
# [1] TRUE
but none of them triggers the Error: myfunc(TRUE) produced warnings
I would expect.