Skip to content

NextMethod causes R 2.2.0 to crash (PR#8416)

1 message · Bill Venables

#
Thanks Hendrik.

My main concern is that it should not be so easy to crash R.

On whether or not NextMethod from within the default method is kosher or
not - I would have thought so, but clearly I'm wrong here.  Perhaps
NextMethod within a default method should be something that at least
attracts a warning.

Regards,

Bill Venables, 
CMIS, CSIRO Laboratories, 
PO Box 120, Cleveland, Qld. 4163 
AUSTRALIA 
Office Phone (email preferred): +61 7 3826 7251 
Fax (if absolutely necessary):    +61 7 3826 7304 
Mobile (rarely used):                +61 4 1963 4642 
Home Phone:                          +61 7 3286 7700 
mailto:Bill.Venables at csiro.au 
http://www.cmis.csiro.au/bill.venables/ 



-----Original Message-----
From: Henrik Bengtsson [mailto:hb at maths.lth.se] 
Sent: Wednesday, 21 December 2005 1:48 PM
To: Venables, Bill (CMIS, Cleveland)
Cc: r-devel at stat.math.ethz.ch; R-bugs at biostat.ku.dk
Subject: Re: [Rd] NextMethod causes R 2.2.0 to crash (PR#8416)
Bill.Venables at csiro.au wrote:
On Windows XP R 2.2.0 Patched (2005-11-21 r36410) you get:

Error: evaluation nested too deeply: infinite recursion / 
options(expressions=)?

and on Windows XP R 2.1.1 Patched (2005-09-19) you get:

Error: protect(): protection stack overflow

It seems that the R.2.2.0 revision you have does not protect against 
this.  I agree that it should not be possible to crash R, but is it 
valid to call NextMethod() in a default function? [R core, should this 
ever be allowed?]

I do not know exactly how NextMethod() is expected to work here, but I 
could imaging that 'x' has class 'Date' when NextMethod() is called and 
the "next" class will the be the default one so you call 
julian.default() again ending up in an infinite call.  This makes sense 
from the errors I get above.  Try this and see what you get in your
version:

julian.default <- function(x, ...) {
   cat("In julian.default()\n")
   x <- as.Date(x)
   NextMethod("julian", x, ...)
}

Was you intention to do the following instead

  julian.default <- function(x, ...) {
    x <- as.Date(x)
    julian(x, ...)
  }

where julian() is the generic function?

Cheers

Henrik