Learn R Programming

R.methodsS3 (version 1.2.2)

setGenericS3: Creates a generic function in S3/UseMethod style

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

## S3 method for class 'default':
setGenericS3(name, envir=parent.frame(), ellipsesOnly=TRUE, dontWarn=getOption("dontWarnPkgs"), validators=getOption("R.methodsS3:validators:setGenericS3"), ...)

Arguments

name
The name of the generic function.
envir
The environment for where this method should be stored.
ellipsesOnly
If TRUE, the only arguments in the generic function will be ....
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 w
validators
An optional list of functions that can be used to assert that the generated generic function meets certain criteria.
...
Not used.

See Also

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

Examples

Run this code
myCat.matrix <- function(..., sep=", ") {
    cat("A matrix:
");
    cat(..., sep=sep);
    cat("");
  }

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

  setGenericS3("myCat");

  myCat(1:10);
  mat <- matrix(1:10, ncol=5);
  attr(mat, "class") <- "matrix";  # Has to be done as of [R] V1.4.0.
  myCat(mat);

Run the code above in your browser using DataLab