Skip to content
Prev 21891 / 63424 Next

Extending [ method to S4 class and drop argument (PR#9211)

Or more in the spirit of method dispatch, and to get some insight into
why this design decision is not a bug:
[1] "test"
+           signature(x="test", drop="missing"),
+           function(x, i, j, ..., drop) {
+               cat("here\n")
+               callNextMethod(x, i, j, ..., drop=TRUE)
+       })
[1] "["
+     cat("there\n")
+     print(drop)
+ })
[1] "["
here
there
[1] TRUE

'drop' is 'missing', and 'missing' satisfies the implicit 'ANY'
condition in the signature of the original method. With this insight,
the design decision to 'ignore' the default argument seems appropriate
to me -- developers implementing the generic might well want to
dispatch on it, since after all it is in the generic signature. This
could lead to an explosion of methods if many arguments have 'default'
values, but such an explosion probably points to a nice distinction
between arguments-for-dispatch and arguments-for-evaluation.

To tell the truth, I hadn't really understood why the error originally
reported occurred, until writing the method with drop="missing" just
now.

Martin

"Gabor Grothendieck" <ggrothendieck at gmail.com> writes:

  
    
Message-ID: <6ph1wqmjmv8.fsf@gopher4.fhcrc.org>
In-Reply-To: <971536df0609080912w386d56d7vf9d064ccfa999dfe@mail.gmail.com> (Gabor Grothendieck's message of "Fri, 8 Sep 2006 12:12:55 -0400")