[Rd] [R] warning.expression?

Duncan Murdoch murdoch at stats.uwo.ca
Fri Sep 23 14:58:39 CEST 2005


I'm sending this reply to r-devel instead of r-help, since it has moved 
into talking about changes to R internals now.

On 9/23/2005 7:36 AM, Barry Rowlingson wrote:
> Thomas Friedrichsmeier wrote:
> 
>> Yes, thanks for pointing it out. However, I'm actually looking for a way to 
>> catch all warnings in a whole (interactive) session. Can warning.expression 
>> be used for that?
> 
>   I've just been nosing around the source code in errors.c, and it 
> doesn't look good.
> 
> In this function:
> 
> static void vwarningcall_dflt(SEXP call, const char *format, va_list ap)
> 
> the warning.expression 's' is called here:
> 
>         cptr = R_GlobalContext;
>          while ( !(cptr->callflag & CTXT_FUNCTION) && cptr->callflag )
>              cptr = cptr->nextcontext;
>          eval(s, cptr->cloenv);
> 	return;
> 
> but when the expression is null/nil the code goes on to the default 
> case, in which it gets the warning message from the 'call' parameter:
> 
> 
>   dcall = CHAR(STRING_ELT(deparse1(call, 0, SIMPLEDEPARSE), 0));
>   REprintf(_("Warning in %s : "), dcall);
> 
>   So I don't see how this parameter can be available to the 
> warning.expression call. There may be a way, but I don't see it.
> 
>   It seems a bit dumb that warning.expression functions can only say 
> "Hey, something a bit iffy may have ocurred, but I dont know what and I 
> dont know where!". Maybe there's something in that cptr->cloenv that can 
> tell you...
> 
>   Otherwise it requires patching.

That's old code (mostly from 1999/2000), and that method of handling 
warnings is not used in any of the base code, which may explain why it 
isn't all that useful.  I don't know of any GUIs that do what Thomas is 
attempting (which I think is to have his GUI divert warnings and errors 
from the output stream to some other display), so there might not 
currently be a good way to do what he wants other than pattern matching 
on the output.

It would probably be a good idea to deprecate warning.expression in the 
next release, rather than beefing it up.  If we don't have a good method 
to do what Thomas wants, we should add it, but warning.expression 
doesn't look like the right way to do it.

Does anyone know of any uses of it in current code on CRAN, 
Bioconductor, or elsewhere?

Duncan Murdoch



More information about the R-devel mailing list