[Rd] strange behaviour of callNextMethod in S4 methods

Vitally S. spinuvit.list at gmail.com
Sun Sep 26 16:37:50 CEST 2010


Harold PETITHOMME <harold.petithomme at meteo.fr> writes:

Hi,
>
> there is no more an error.
> Why does my "object" disappear?

I cannot reproduce your problem.

Here is an example identical to yours:

setClass("foo", list(a = "character", b = "numeric"), proto = 100,
         contains = "numeric")
setClass("boo", list(c = "numeric"), contains = "foo")


setGeneric("meth",
           def=function(variable, object, nc) standardGeneric("

setMethod("meth",signature(variable="ANY",object="numeric", nc="foo"),
            def=function(variable,object, nc)
            {
              nc at a <- as.character(variable)
              nc at b <- object+5
              nc
            }
            )

meth( 2432, 22, new("foo"))

setMethod("meth", signature(variable="ANY",object="numeric", nc="boo"),
            def=function(variable, object, nc)
            {
              nc at c <- object+10
              callNextMethod()
            }
            )
meth(4232, 22, new("boo")) ##works ok


Everything works as expected.

Vitaly.

>
> Thanks to all.
> Harold



More information about the R-devel mailing list