S3method: Register S3 Methods

Description Usage Arguments Details Examples

Description

Register S3 methods in R scripts.

Usage

1
.S3method(generic, class, method)

Arguments

generic

a character string naming an S3 generic function.

class

a character string naming an S3 class.

method

a character string or function giving the S3 method to be registered. If not given, the function named generic.class is used.

Details

This function should only be used in R scripts: for package code, one should use the corresponding S3methodNAMESPACE’ directive.

Examples

1
2
3
4
5
6
7
8
9
## Create a generic function and register a method for objects
## inheriting from class 'cls':
gen <- function(x) UseMethod("gen")
met <- function(x) writeLines("Hello world.")
.S3method("gen", "cls", met)
## Create an object inheriting from class 'cls', and call the
## generic on it:
x <- structure(123, class = "cls")
gen(x)