Parlamis Franklin
2006-Oct-11 00:53 UTC
[Rd] dispatching on group generics with more than one formal
please see the code below. foo2 fails to dispatch correctly, but foo
does fine. i have tried 'cacheMetaData(1)' and a number of different
variants of 'cacheGenericsMetaData', on the possibility there is a
caching issue. but i still can't sort it out.
also one general question: does it really matter what's in the body
of the function definition in a 'setGroupGeneric' call? the actual
group function definition is always overwritten by a message to the
effect the function should not be called directly.
__
setGroupGeneric("Foo", function(x) standardGeneric("Foo"))
setGroupGeneric("Foo2", function(x, y)
standardGeneric("Foo2"))
setGeneric("foo", function(x) standardGeneric("foo"),
group = "Foo", useAsDefault = function(x) "Default")
setGeneric("foo2", function(x, y) standardGeneric("foo2"),
group = "Foo2", useAsDefault = function(x, y) "Default2")
setMethod("Foo", signature(x = "numeric"), function(x)
"Special")
setMethod("Foo2", signature(x = "numeric", y =
"missing"),
function(x, y) "Special2")
foo(1) # gives the group method
foo2(1) # gives the default method
selectMethod("foo2", signature(x = "numeric", y =
"missing")) # but
method selection appears to work correctly
__
franklin parlamis
> version
platform powerpc-apple-darwin8.7.0
arch powerpc
os darwin8.7.0
system powerpc, darwin8.7.0
status
major 2
minor 4.0
year 2006
month 10
day 03
svn rev 39566
language R
version.string R version 2.4.0 (2006-10-03)
John Chambers
2006-Oct-11 17:40 UTC
[Rd] dispatching on group generics with more than one formal
Yes, a bug.
The problem is that all generics start off with only 1 active argument
in the signature (for efficiency). As soon as a method is specified
with >1 args in the signature, the number of active arguments is
supposed to be incremented accordingly. But specifying the method for
the _group_ generic doesn't trigger this in the members of the group, as
it should.
Should be fairly easy to fix, but I won't likely have time for a few days.
Meanwhile, a workaround is to define a method for the member generic
with >1 arguments in the signature:
> setMethod("foo2", c("character", "missing"),
function(x, y) "CharacterMethod")
[1] "foo2"
> foo2(1)
[1] "Special2"
Parlamis Franklin wrote:> please see the code below. foo2 fails to dispatch correctly, but foo
> does fine. i have tried 'cacheMetaData(1)' and a number of
different
> variants of 'cacheGenericsMetaData', on the possibility there is a
> caching issue. but i still can't sort it out.
>
> also one general question: does it really matter what's in the body
> of the function definition in a 'setGroupGeneric' call? the actual
> group function definition is always overwritten by a message to the
> effect the function should not be called directly.
> __
>
> setGroupGeneric("Foo", function(x)
standardGeneric("Foo"))
> setGroupGeneric("Foo2", function(x, y)
standardGeneric("Foo2"))
> setGeneric("foo", function(x) standardGeneric("foo"),
> group = "Foo", useAsDefault = function(x) "Default")
> setGeneric("foo2", function(x, y)
standardGeneric("foo2"),
> group = "Foo2", useAsDefault = function(x, y)
"Default2")
> setMethod("Foo", signature(x = "numeric"), function(x)
"Special")
> setMethod("Foo2", signature(x = "numeric", y =
"missing"),
> function(x, y) "Special2")
> foo(1) # gives the group method
> foo2(1) # gives the default method
> selectMethod("foo2", signature(x = "numeric", y =
"missing")) # but
> method selection appears to work correctly
>
> __
>
> franklin parlamis
>
> > version
>
> platform powerpc-apple-darwin8.7.0
> arch powerpc
> os darwin8.7.0
> system powerpc, darwin8.7.0
> status
> major 2
> minor 4.0
> year 2006
> month 10
> day 03
> svn rev 39566
> language R
> version.string R version 2.4.0 (2006-10-03)
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>