You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
(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] TRUEexpect_silent4<-function(obj) { eval(bquote(expect_silent(o<- .(obj)))) ; o ; }
expect_silent4(myfunc(TRUE))
# Warning in myfunc(TRUE) : quux# [1] TRUEexpect_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.
The text was updated successfully, but these errors were encountered:
r2evans
changed the title
expect_silent omitting the output
change expect_silent to include object output
Aug 10, 2017
(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
but this does not work using the NSE hack for replacing
info
. That is:That last error message isn't very useful, so I try the NSE trick:
but none of them triggers the
Error: myfunc(TRUE) produced warnings
I would expect.The text was updated successfully, but these errors were encountered: