From murdoch.duncan at gmail.com  Thu Apr 18 14:57:12 2013
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Thu, 18 Apr 2013 08:57:12 -0400
Subject: [Rd] Suppress specific warnings
In-Reply-To: <53248767-3336-47A3-ADD7-FDD3143FCAD0@nicebread.de>
References: <53248767-3336-47A3-ADD7-FDD3143FCAD0@nicebread.de>
Message-ID: <516FEDA8.70003@gmail.com>

On 13-04-18 7:31 AM, Felix Sch?nbrodt wrote:
> Hello,
>
> is there a convenient way to suppress only *specific* warnings? (I know about ?suppressWarnings)
> I depend on another package, from which I want to suppress only some warnings, but not others.

This is difficult in most cases, because most packages don't give enough 
information to distinguish among their warnings.  You could probably do 
it based on the message as follows, but the test won't work if someone 
is running in a locale where the warning message has been translated to 
a different language:

x <- 1:10
x + 1:3   # gives the warning:

In x + 1:3 :
   longer object length is not a multiple of shorter object length

To suppress just this one, try this:

withCallingHandlers(x + 1:3,
    warning=function(w) {
       if (grepl("longer object length", w$message))
          invokeRestart("muffleWarning")
    } )

Duncan Murdoch



[Rd] Suppress specific warnings
Duncan Murdoch