From karl.forner at gmail.com  Mon Dec  2 10:18:16 2013
From: karl.forner at gmail.com (Karl Forner)
Date: Mon, 2 Dec 2013 10:18:16 +0100
Subject: [Rd] How to catch warnings sent by arguments of s4 methods ?
In-Reply-To: <CAMd4_AfmWJ7bYS31QH1Gt+==QVXR=E-RQtgV8MsUUQ_iwsf9rw@mail.gmail.com>
References: <CAMd4_AfmWJ7bYS31QH1Gt+==QVXR=E-RQtgV8MsUUQ_iwsf9rw@mail.gmail.com>
Message-ID: <CAMd4_AekqTPSAFNv=wfAc0HoNZcdk6=NQaubozuPc1feVo1vJw@mail.gmail.com>

Hi,
Just to add some information and to clarify why I feel this is an
important issue.

If you have a S4 method with a default argument, it seems that you can
not catch the warnings
emitted during their evaluation. It matters because on some occasions
those warnings carry an essential information,
that your code needs to use.

Martin Morgan added some information about this issue on:
http://stackoverflow.com/questions/20268021/how-to-catch-warnings-sent-during-s4-method-selection
Basically the C function R_dispatchGeneric  uses R_tryEvalSilent to
evaluate the method arguments, that seems no to use the calling
handlers.

Best,
Karl


On Fri, Nov 29, 2013 at 11:30 AM, Karl Forner <karl.forner at gmail.com> wrote:
> Hello,
>
> I apologized if this had already been addressed, and I also submitted
> this problem on SO:
> http://stackoverflow.com/questions/20268021/how-to-catch-warnings-sent-during-s4-method-selection
>
> Example code:
> setGeneric('my_method', function(x) standardGeneric('my_method') )
> setMethod('my_method', 'ANY', function(x) invisible())
>
> withCallingHandlers(my_method(warning('argh')), warning = function(w)
> { stop('got warning:', w) })
> # this does not catch the warning
>
> It seems that the warnings emitted during the evaluation of the
> arguments of S4 methods can not get caught using
> withCallingHandlers().
>
> Is this expected ? Is there a work-around ?
>
> Best,
> Karl Forner



[Rd] How to catch warnings sent by arguments of s4 methods ?
Karl Forner