From ripley at stats.ox.ac.uk  Thu Jun 28 16:31:29 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Thu, 28 Jun 2007 15:31:29 +0100 (BST)
Subject: [Rd] signature() and setMethod() problems
In-Reply-To: <18051.45736.205670.324365@stat.math.ethz.ch>
References: <5EB87C76-7CEA-4C1B-930E-3C19409338D0@noc.soton.ac.uk>
	<18051.45736.205670.324365@stat.math.ethz.ch>
Message-ID: <Pine.LNX.4.64.0706281526520.10053@gannet.stats.ox.ac.uk>

On Thu, 28 Jun 2007, Martin Maechler wrote:

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

For completeness, let me mention that in the special case of one-argument 
primitives the name in the signature is ignored, essentially because the 
name is not used by the primitive itself and so there have been different 
interpretations (e.g. `!`(x) and `!`(e1) ).  In all other cases, methods 
should agree with the generic as Martin advises.

>
> 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
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] signature() and setMethod() problems
Prof Brian Ripley