[Rd] signature() and setMethod() problems

Martin Maechler maechler at stat.math.ethz.ch
Thu Jun 28 15:07:52 CEST 2007

>>>>> "Robin" == Robin Hankin <r.hankin at noc.soton.ac.uk>
>>>>>     on Thu, 28 Jun 2007 13:38:32 +0100 writes:

    Robin> I am having difficulty using signature().  I have one
    Robin> virtual class (onion) and two nonvirtual classes
    Robin> (quaternion and octonion).  containing onion.

    Robin> I want to define three distinct sets of arithmetic
    Robin> operations: one for onion-onion, one for onion-real,
    Robin> and one for real-onion [this is more computationally
    Robin> efficient than coercing reals to onions and then
    Robin> using onion-onion operations].

    Robin> Executing the following code gives an error [R-2.5.0]
    Robin> at the first call to setMethod():

    Robin> Error in match.call(fun, fcall) : unused argument(s)
    Robin> (o1 = "onion", o2 = "onion")

    Robin> Why is this,

you are not free to call your arguments whatever you like:
The generic function prescribes the signature,
in the case of Arith,
its  (e1, e2)

    Robin> and what would the List suggest is Best Practice here?

use the correct signature :-)


    Robin> setClass("onion", representation = "VIRTUAL" )

    Robin> setClass("quaternion", representation =
    Robin> representation(x="matrix"), prototype =
    Robin> list(x=matrix(numeric(),0,4)), contains = "onion" )

    Robin> setClass("octonion", representation =
    Robin> representation(x="matrix"), prototype =
    Robin> list(x=matrix(numeric(),0,8)), contains = "onion" )

    Robin> ".onion.onion.arith" <- function(o1,o2){stop("OO not
    Robin> implemented")} ".onion.real.arith" <-
    Robin> function(o,r){stop("OR not implemented")}
    Robin> ".real.onion.arith" <- function(r,o){stop("RO not
    Robin> implemented")}

    Robin> setMethod("Arith", signature (o1="onion",o2="onion"
    Robin> ), .onion.onion.arith) setMethod("Arith",
    Robin> signature(o="onion",r="ANY" ), .onion.real.arith)
    Robin> setMethod("Arith", signature(r="ANY",o="onion" ),
    Robin> .real.onion.arith)

    Robin> -- Robin Hankin Uncertainty Analyst National
    Robin> Oceanography Centre, Southampton European Way,
    Robin> Southampton SO14 3ZH, UK tel 023-8059-7743

    Robin> ______________________________________________
    Robin> R-devel at r-project.org mailing list
    Robin> https://stat.ethz.ch/mailman/listinfo/r-devel

More information about the R-devel mailing list