method {S7}R Documentation

Retrieve a method for an S7 generic

Description

method() takes a generic and signature and retrieves the corresponding method. This is rarely needed because most of the time you'll rely on the the generic, via S7_dispatch(), to find and call the method for you. However, this introspection is useful if you want to see the implementation of a specific method.

Usage

method(generic, class = NULL, object = NULL)

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 with as_class()) or a concrete object. If generic uses multiple dispatch then both object and class must be a list of classes/objects.

Value

A function with class <S7_method>.

See Also

method_explain() to explain why a specific method was picked.

Examples

# Create a generic and register some methods
bizarro <- new_generic("bizarro", "x")
method(bizarro, class_numeric) <- function(x) rev(x)
method(bizarro, new_S3_class("factor")) <- function(x) {
  levels(x) <- rev(levels(x))
  x
}

# Printing the generic shows the registered method
bizarro

# And you can use method() to inspect specific implementations
method(bizarro, class = class_integer)
method(bizarro, object = 1)
method(bizarro, new_S3_class("factor"))

[Package S7 version 0.1.1 Index]