setVirtualMethod       package:externalVector       R Documentation

_S_e_t _a _v_i_r_t_u_a_l _m_e_t_h_o_d _f_o_r _a _g_i_v_e_n _s_i_g_n_a_t_u_r_e

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

    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. 

_D_e_t_a_i_l_s:

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

_V_a_l_u_e:

     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.

_S_e_e _A_l_s_o:

     'setGeneric', 'setMethod'

_E_x_a_m_p_l_e_s:

     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)

