potential patch for markmfredrickson/RItools#124 #132
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Regarding #124, I think the warning suppression might not be from the
finally
argument, but from resetting the options. I also think having atryCatch()
block as currently structured + having a call toon.exit()
is redundant, since there's no real additional error/warning handling happening, but let me know if I'm missing any important context there.I pulled the following example from
test.balanceTest.R
, specificallytest_that("Consistency between lm() and balTest()")
in order to generate a warning:This should should generate:
Warning message: In makeDesigns(fmla, data) : 1 levels of survival::strata(blk) did not include both treated and control units
I used this example to try and isolate the behavior identified in the issue:
This version of withOptions() will print the warning message
... but this one will not:
This one will:
...but this one will not:
So, the warning suppression seems to be related to the line options(oldOpts).
Rather than blanket resetting all of the options, resetting just the options that were changed seems to solve the warning suppression (removing the redundant
on.exit()
as well), as the following code:generates warnings when running the test code above:
This seems to work and doesn't break any tests (from running
devtools::check()
). But, admittedly, I'm not totally sure why. In versions withoptions(oldOpts)
, callingwarnings()
after runningbalanceTest()
returns nothing, but calling it after the versions withoptions(old.opt.values)
returns the expected warning. So, somehow they're getting cleared in the process of resetting all of the options.