[R] warning.expression?

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Fri Sep 23 13:36:40 CEST 2005

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);

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.


More information about the R-help mailing list