2

I look for some easy method to find out if any code generates a warning. Some method to call TRUE|FALSE in case of causing warning. I discovered expect_warning(), that doesn't work anymore.

I need to run for cyklus with nonparametric tests, and always return TRUE, if a partial nonparametric test generates warning. Specifically warning of dealing with ties when conducting Wilcoxon.

chromanna
  • 61
  • 5
  • Does this help? https://stackoverflow.com/questions/3903157/how-can-i-check-whether-a-function-call-results-in-a-warning or https://stackoverflow.com/questions/4948361/how-do-i-save-warnings-and-errors-as-output-from-a-function – Jon Spring May 15 '21 at 18:11
  • 1
    I have similar situations where I do something like `tryCatch(warning("quux"), warning=function(w) if (grepl("quu", conditionMessage(w))) do_something() else warning(w))`. One possible problem here is that catching the warning discards the results of the `expr`ession, which (in your case) may not be a problem. The `warning(w)` is effectively a bump of sorts, but since it still discards the expression's return, it is effectively a stopper. – r2evans May 15 '21 at 18:38
  • If you need to preserve the expression results when a warning is emitted, look into `withCallingHandlers`, also in that dupe link, specifically https://stackoverflow.com/a/4947528/3358272. (If it still doesn't help, ping me and we can look at reopening given more details in the question.) Good luck! – r2evans May 15 '21 at 18:39
  • 1
    @r2evans Yes! It finally works in the simplest form possible. **Thanks a lot**. I almost fell into despair and into the stackoverflow's depths. – chromanna May 15 '21 at 20:42

0 Answers0