Re: [Rd] S4 methods semantics questions

From: Seth Falcon <>
Date: Fri 25 Mar 2005 - 18:36:23 GMT

John Chambers <> writes:

> Well, the intent is that defaults are indeed taken from the method, if
> there is a default there, otherwise from the generic. It looks as if
> there is a bug in the case that the generic has NO default for that
> argument (unless, of course, it's a subtle feature, but not that I can
> think of at the moment).
> Your example works as intended if there is a default expression for y
> in the generic:
> R> setGeneric("foo",function(x,y=stop("Need y")) standardGeneric("foo"))
> [1] "foo"
> R> setMethod("foo","numeric",function(x,y=2) x+y)
> [1] "foo"
> R> foo(1)
> [1] 3

FWIW, I've encountered the same error that the OP described. I certainly don't know if it is a bug, but I can say that I expected it to work based on the documentation of setMethod.

I ended up with a different workaround: if you don't need to do dispatching on the default arguments, you can set

setGeneric("foo", function(x, ...) standardGeneric("foo"))

and then methods with defaults defined in their function do the expected thing.


+ seth mailing list Received on Sat Mar 26 05:41:12 2005

This archive was generated by hypermail 2.1.8 : Mon 24 Oct 2005 - 22:26:32 GMT