[R] callNextMethod

laurent buffat laurent.buffat at it-omics.com
Wed May 21 12:03:33 CEST 2003


Hi,

I don't understand why this code doesn't work (f(b2)):

/////////////////

setClass("B0", representation(b0 = "numeric"))
setClass("B1", representation("B0", b1 = "character"))
setClass("B2", representation("B1", b2 = "logical"))

f <- function(x) class(x)

setMethod("f", "B0", function(x) c(x at b0, callNextMethod()))
setMethod("f", "B1", function(x) c(x at b1,x at b0*x at b0,callNextMethod()))
setMethod("f", "B2", function(x) c(x at b2, callNextMethod()))

b0 <- new("B0", b0 = 3)
b1 <- new("B1", b1 = "deux", b0 = 2)
b2 <- new("B2", b2 = FALSE, b1 = "dix", b0 = 10)

f(b0)
f(b1)
f(b2)

///////////////////////////

> f(b0)
[1] "3"  "B0"
> f(b1)
[1] "deux" "4"    "2"    "B1"  
> f(b2)
Error in get(x, envir, mode, inherits) : variable ".Generic" was not found

//////////////////////////////

I'm using R Version 1.7.0, on a linux machine.

Thanks for your help.

Laurent B.




More information about the R-help mailing list