\name{setVirtualMethod}
\alias{setVirtualMethod}
\title{ 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(), \dots, where = topenv(parent.frame()))
}
\arguments{
  \item{name}{ The character-string name of the generic function. }
  \item{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. }
  \item{signature.nonvirtual}{ Signature for other arguments. Any
    ommitted argument is assumed to have class "ANY". }
  \item{\dots}{ Other arguments. See details. }
  \item{where}{ The database in which to store the definition of the
    method. }
}
\details{
  If the generic for \code{name} is not defined, an attempt is made to
  create it with \code{setGeneric(name, \dots, 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 \code{setMethod} to
  create the virtual method.
}
\seealso{ \code{\link[methods]{setGeneric}}, \code{\link[methods]{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)
}
\keyword{methods}