[Rd] Unexplained strange behaviour of callNextMethod in S4 methods

Harold Petithomme harold.petithomme at meteo.fr
Mon Oct 4 12:49:18 CEST 2010


Hello all.

A few days ago, I submitted a problem which remains unsolved although 
somebody answered to my question. I still have the problem. Can someone 
please explain if something is wrong ?

Have a look at this example:

setGeneric("f",valueClass="NULL",def=function(x) standardGeneric("f"))

setMethod("f",signature(x="A"),def=function(x)
{
    a = x at a
    cat("nombre :",a,"\n")
}
)

setMethod("f",signature(x="B"),def=function(x)
{
    cat("mot :",x at b,"\n")
    callNextMethod()
}
)

a = new("A",a=1)
b = new("B",b="hello",a)

f(a)
f(b)

This last command (f(b)) fails. But remove the 'valueClass="NULL"' 
setting in setGeneric or add argument x to the call to callNextMethod 
and it will be OK! Isn't it tricky?

Thanks in advance for any help.

Harold

-- 
*********************************************************
Harold PETITHOMME
Equipe Données et Outils de Prévision (DPREVI/COMPAS/DOP)

Météo France - Direction de la Production
42, avenue G. Coriolis.
31057 Toulouse Cedex
France

Tel : (33/0)5.61.07.82.85
Fax : (33/0)5.61.07.86.09
E-mail : harold.petithomme at meteo.fr



More information about the R-devel mailing list