[R] Group methods for basic classes

Parlamis Franklin fparlamis at mac.com
Wed Apr 12 04:25:13 CEST 2006


Trying to define group methods for the "expression" class, running  
into some problems.

 > setMethod("Arith", signature(e1 = "expression", e2 = "expression"),
+ function(e1, e2) 5)
[1] "Arith"
 > expression(2)+expression(5)
Error in expression(2) + expression(5) : non-numeric argument to  
binary operator

Is something sealed somewhere?  If so, what was the effect of my  
setMethod call, which gave no Error or Warning?

Here is what I am using as a workaround.

 > setClass("Expression", representation("expression"))
[1] "Expression"
 > setMethod("Arith", signature(e1 = "Expression", e2 = "Expression"),
+ function(e1, e2) 5)
[1] "Arith"
 > new("Expression", expression(2)) + new("Expression", expression(5))
[1] 5

Is this the preferred workaround, or is there something better?

Franklin




More information about the R-help mailing list