setVirtualMethod {externalVector}R Documentation

Set a virtual method for a given signature

Description

This sets a method for a signature. If there is no generic with the given name, it also creates the appropriate generic. If called, the method generates an error indicating the classes of the arguments which are part of the signature.

Usage

setVirtualMethod(name, signature.virtual, signature.nonvirtual = character(), ..., where = topenv(parent.frame()))

Arguments

name The character-string name of the generic function.
signature.virtual Signature of the arguments for which the virtual method is being set. All of these arguments must have a virtual class in the signature.
signature.nonvirtual Signature for other arguments. Any ommitted argument is assumed to have class "ANY".
... Other arguments. See details.
where The database in which to store the definition of the method.

Details

If the generic for name is not defined, an attempt is made to create it with setGeneric(name, ..., where = where).

Value

This method exists for its side-effect of setting up the virtual method.
The return value is the result from the call to setMethod to create the virtual method.

See Also

setGeneric, setMethod

Examples

setClass("myMatrix")
setVirtualMethod("dim", "myMatrix")
setVirtualMethod("dimnames", "myMatrix")
setClass("myMatrix2", representation(val="numeric",
                                     d = "integer",
                                     dn = "list"),
         contains="myMatrix")
x <- new("myMatrix2", val=1:4, d = as.integer(c(2, 2)),
         dn = list(LETTERS[1:2], letters[1:2]))
## A call dim(x) or dimnames(x) would generate an error here
setMethod("dim", "myMatrix", function(x) x@d)
setMethod("dimnames", "myMatrix", function(x) x@dn)
dim(x)
dimnames(x)

[Package externalVector version 1.0.14 Index]