I am having difficulty using signature(). I have one virtual class (onion) and two nonvirtual classes (quaternion and octonion). containing onion. I want to define three distinct sets of arithmetic operations: one for onion-onion, one for onion-real, and one for real-onion [this is more computationally efficient than coercing reals to onions and then using onion-onion operations]. Executing the following code gives an error [R-2.5.0] at the first call to setMethod(): Error in match.call(fun, fcall) : unused argument(s) (o1 = "onion", o2 = "onion") Why is this, and what would the List suggest is Best Practice here? setClass("onion", representation = "VIRTUAL" ) setClass("quaternion", representation = representation(x="matrix"), prototype = list(x=matrix(numeric(),0,4)), contains = "onion" ) setClass("octonion", representation = representation(x="matrix"), prototype = list(x=matrix(numeric(),0,8)), contains = "onion" ) ".onion.onion.arith" <- function(o1,o2){stop("OO not implemented")} ".onion.real.arith" <- function(o,r){stop("OR not implemented")} ".real.onion.arith" <- function(r,o){stop("RO not implemented")} setMethod("Arith", signature (o1="onion",o2="onion" ), .onion.onion.arith) setMethod("Arith", signature(o="onion",r="ANY" ), .onion.real.arith) setMethod("Arith", signature(r="ANY",o="onion" ), .real.onion.arith) -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
>>>>> "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
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