[R] callNextMethod

John Chambers jmc at research.bell-labs.com
Thu May 22 00:02:19 CEST 2003


laurent buffat wrote:
> 
> Hi,
> 
> I don't understand why this code doesn't work (f(b2)):

Indeed, it should work.  There were some problems in chaining multiple
callNextMethod()s.

A fix has been committed to the R-patched source, and will be in version
1.7.1, in a few weeks.

A good bug report; thanks.

John Chambers

> 
> /////////////////
> 
> 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.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
John M. Chambers                  jmc at bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc




More information about the R-help mailing list