setGeneric(name, def = NULL, group = list(), valueClass = character(), where = topenv(parent.frame()), package = NULL, signature = NULL, useAsDefault = NULL, genericFunction = NULL, simpleInheritanceOnly = NULL)
name | a character string specifying the name of the generic function. |
def | the definition of the generic function. Typically, the function body consists of just one line: standardGeneric(name). If this argument is not given, a suitable function is constructed with arguments from the default method. (If there is no default function, this generates an error.) |
group | this argument is unimplemented, and a warning is generated if it is given. |
valueClass | this argument is unimplemented, and a warning is generated if it is given. |
where | the environment for storing the generic function definition. |
package | if package is the name of a loaded package, and def and useAsDefault are not given, the definition of name is read from this package. |
signature | a string vector. The arguments of the generic function that can be dispatched on. If this is not given, the signature is created from all the arguments of def. |
useAsDefault |
|
genericFunction | this argument is unimplemented, and a warning is generated if it is given. |
simpleInheritanceOnly | this argument is unimplemented, and a warning is generated if it is given. |
# Define an S4 generic setGeneric("myDim", function(object) standardGeneric("myDim"))# Define S4 methods setMethod("myDim", "matrix", function(object) dim(object)) setMethod("myDim", "vector", function(object) length(object))
# call the generic myDim(matrix(1:4,2)) myDim(1:4)