From maechler at stat.math.ethz.ch  Thu Jun 28 15:07:52 2007
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 28 Jun 2007 15:07:52 +0200
Subject: [Rd] signature() and setMethod() problems
In-Reply-To: <5EB87C76-7CEA-4C1B-930E-3C19409338D0@noc.soton.ac.uk>
References: <5EB87C76-7CEA-4C1B-930E-3C19409338D0@noc.soton.ac.uk>
Message-ID: <18051.45736.205670.324365@stat.math.ethz.ch>

>>>>> "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 :-)

Regards,
Martin




    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



[Rd] signature() and setMethod() problems
Martin Maechler