Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

setGenericS3

Creates an S3 generic function


Description

Note that this method is a internal method called by setMethodS3() and there is no reason for calling it directly!

Creates a generic function in S3 style, i.e. setting a function with name name that dispatches the method name via UseMethod. If there is already a function named name that function is renamed to name.default.

Usage

## Default S3 method:
setGenericS3(name, export=TRUE, envir=parent.frame(), dontWarn=getOption("dontWarnPkgs"),
  validators=getOption("R.methodsS3:validators:setGenericS3"), overwrite=FALSE, ...)

Arguments

name

The name of the generic function.

export

A logical setting attribute "export".

envir

The environment for where this method should be stored.

dontWarn

If a non-generic method with the same name is found it will be "renamed" to a default method. If that method is found in a package with a name that is not found in dontWarn a warning will be produced, otherwise it will be renamed silently.

validators

An optional list of functions that can be used to assert that the generated generic function meets certain criteria.

...

Not used.

overwrite

If TRUE an already existing generic function with the same name will be overwritten, otherwise not.

Author(s)

Henrik Bengtsson

See Also

To define a method for a class see setMethodS3(). For more information about S3, see UseMethod().

Examples

myCat.matrix <- function(..., sep=", ") {
  cat("A matrix:\n")
  cat(..., sep=sep)
  cat("\n")
}

myCat.default <- function(..., sep=", ") {
  cat(..., sep=sep)
  cat("\n")
}

setGenericS3("myCat")

myCat(1:10)
mat <- matrix(1:10, ncol=5)
myCat(mat)

R.methodsS3

S3 Methods Simplified

v1.8.1
LGPL (>= 2.1)
Authors
Henrik Bengtsson [aut, cre, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.