moodymudskipper / tags

A collection of tags built using the package tag
GNU General Public License v3.0
8 stars 0 forks source link

suppressing_warnings #23

Closed moodymudskipper closed 5 years ago

moodymudskipper commented 5 years ago

a tag based on :

suppress_warnings <- function(.expr, .f, ...) {
  eval.parent(substitute(
    withCallingHandlers( .expr, warning = function(w) {
      cm <- conditionMessage(w)
      cond <- 
        if(is.character(.f)) grepl(.f, cm) else rlang::as_function(.f)(cm,...)
      if (cond) {
        invokeRestart("muffleWarning")
      }
    })
  ))
}

https://stackoverflow.com/questions/16517795/selective-suppresswarnings-that-filters-by-regular-expression/55182432#55182432

More sophisticated than the strictly tag, and named more in line with other tags

moodymudskipper commented 5 years ago

to work directly as given here, we need to sort out the issue about ... in tag

moodymudskipper commented 5 years ago

a nice example could be a select call using one_of as it has awkward warnings when column doesn't exist

moodymudskipper commented 5 years ago

done