[R] Problem with generic methods
Uwe Ligges
ligges at statistik.tu-dortmund.de
Fri Jun 5 23:32:30 CEST 2009
Rainer M Krug wrote:
> 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"
.... because the method function you want to call is beginYear.Fun
rather than beginYear as declared in the method specification?
Uwe Ligges
>> beginYear.Fun(4)
> [1] 16
>
>> beginYear(4)
> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
>
More information about the R-help
mailing list