method_explain()
shows all possible methods that a call to a generic
might use, which ones exist, and which one will actually be called.
Note that method dispatch uses a string representation of each class in the class hierarchy. Each class system uses a slightly different convention to avoid ambiguity.
S7:
pkg::class
orclass
S4:
S4/pkg::class
orS4/class
S3:
class
Arguments
- generic
A generic function, i.e. an S7 generic, an external generic, an S3 generic, or an S4 generic.
- class, object
Perform introspection either with a
class
(processed withas_class()
) or a concreteobject
. Ifgeneric
uses multiple dispatch then bothobject
andclass
must be a list of classes/objects.
Examples
Foo1 <- new_class("Foo1")
Foo2 <- new_class("Foo2", Foo1)
add <- new_generic("add", c("x", "y"))
method(add, list(Foo2, Foo1)) <- function(x, y) c(2, 1)
method(add, list(Foo1, Foo1)) <- function(x, y) c(1, 1)
method_explain(add, list(Foo2, Foo2))
#> add([Foo2], [Foo2])
#> -> add([Foo2], [Foo1])
#> add([Foo2], [S7_object])
#> add([Foo2], [ANY])
#> add([Foo1], [Foo2])
#> * add([Foo1], [Foo1])
#> add([Foo1], [S7_object])
#> add([Foo1], [ANY])
#> add([S7_object], [Foo2])
#> add([S7_object], [Foo1])
#> add([S7_object], [S7_object])
#> add([S7_object], [ANY])
#> add([ANY], [Foo2])
#> add([ANY], [Foo1])
#> add([ANY], [S7_object])
#> add([ANY], [ANY])