getS3method
Get An S3 Method

Description

Retrieves an S3 method of generic function for a given class.

Usage

getS3method(f, class, optional = FALSE)

Arguments

f a character string giving the name of generic function.
class a character string giving the class name for which the method is implemented.
optional a logical value. If TRUE, the function returns NULL when no generic function or method is found. If FALSE (the default), the function stops with error message.

Details

This function is used to get an S3 method with the given generic function f and the class name class. Normally, the S3 method name has the format f.class.
First, the f generic function is found and checked in the known generic list. If it is not found, NULL is returned, or the function is stopped with an error message, depending on the optional.
After that, the method f.class is found in the S3 method table. If it is not found, NULL is returned or the function is stopped with an error message, depending on the optional.
Value
returns the found S3 method. If it cannot be found, returns NULL or stops with an error message.
See Also
get, methods
Examples

exists("print.lm") # TRUE head(getS3method("print","lm"))

exists("print.hclust") # FALSE head(getS3method("print","hclust"))

try(getS3method("foo")) # Error: no function 'foo' could be found getS3method("foo", optional = TRUE) # NULL

try(getS3method("print", "foo_class")) # Error: S3 method 'print.foo_class' not found getS3method("print", "foo_class", optional = TRUE) # NULL

Package utils version 6.1.1-7
Package Index