Skip to content
Prev 44303 / 63424 Next

suppress *specific* warnings?

On 10/22/2012 09:57 AM, luke-tierney at uiowa.edu wrote:
Probably specific messages, rather than patterns, would be handled and then

   suppressWarnings2 <- function(expr, messages = character())
   {
       opts <- options(warn = -1)
       on.exit(options(ops))
       withCallingHandlers(expr, warning=function(w) {
           if (conditionMessage(w) %in% messages)
               invokeRestart("muffleWarning")
       })
   }

gives one the illusion of speaking many languages

   suppressWarnings2(log(-1), gettext("NaNs introduced", domain="R"))

Martin