[R] Problem with generic methods
Rainer M Krug
r.m.krug at gmail.com
Fri Jun 5 16:20:40 CEST 2009
Hi
I want to create a new generic method, but I end up with an error
(evaluation nested too deeply). see the transcript below.
The function beginYear.Fun() works, but not beginYear.
I have no idea why.
Any ideas welcome,
Rainer
> setClass("fun", representation(x = "numeric"))
[1] "fun"
> new("fun")
An object of class “fun”
Slot "x":
numeric(0)
> setGeneric(
"beginYear",
function(object, ...) standardGeneric("beginYear")
)
setGeneric(
+ "beginYear",
+ function(object, ...) standardGeneric("beginYear")
+ )
[1] "beginYear"
> beginYear.Fun = function(x) x^2
> beginYear.Fun(4)
[1] 16
> setMethod(
"beginYear",
signature( object = "numeric" ),
beginYear
)
setMethod(
+ "beginYear",
+ signature( object = "numeric" ),
+ beginYear
+ )
[1] "beginYear"
> beginYear.Fun(4)
[1] 16
> beginYear(4)
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
>
--
Rainer M. Krug, Centre of Excellence for Invasion Biology,
Stellenbosch University, South Africa
More information about the R-help
mailing list