Re: [Rd] signature() and setMethod() problems

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Thu, 28 Jun 2007 15:07:52 +0200

>>>>> "Robin" == Robin Hankin <r.hankin@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

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 28 Jun 2007 - 13:14:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Jun 2007 - 20:37:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.