Hello,

I experienced a strange behaviour of callNextMethod when used in either initialize or any other S4 function method definition. Help says callNextMethod calls the next inherited method for the current function from where it is called with the same actual (non missing) arguments. This is OK. The problem appears when some formal arguments (in particular, S4 objects) of this function are first used in the current method and then must be used in the "next method" too. It happens that such an argument is said to be missing in the "next method". My guess is that using the argument in the current method makes it disappear the next method. Is it a bug or a normal behaviour?

For understanding, let's see this example (with calls to some RNetCDF functions):

Define a generic:
setGeneric("ncputVar",def=function(nc,variable,object) standardGeneric("ncputVar"))

Define a 1st method for class Source:
setMethod("ncputVar",signature(nc="NetCDF",variable="ANY",object="Source"),
   def=function(nc,variable,object)
{
   att.put.nc(nc,variable,"nom","NC_CHAR",obj...@nom)
   att.put.nc(nc,variable,"dom","NC_CHAR",obj...@dom)
   att.put.nc(nc,variable,"loc","NC_CHAR",obj...@loc)
   att.put.nc(nc,variable,"time","NC_CHAR",obj...@time)
}
)

Define an inherited method for class OPSource:
setMethod("ncputVar",signature(nc="NetCDF",variable="ANY",object="OPSource"),
   def=function(nc,variable,object)
{
   att.put.nc(nc,variable,"srctype","NC_CHAR","OPSource")
   att.put.nc(nc,variable,"oporig","NC_CHAR",obj...@oporig)
   callNextMethod()
}
)

A call to ncputVar with an OPSource object causes an error saying object is not present.
But if the method definition is changed like this:

setMethod("ncputVar",signature(nc="NetCDF",variable="ANY",object="OPSource"),
   def=function(nc,variable,object)
{
   o = object
   att.put.nc(nc,variable,"srctype","NC_CHAR","OPSource")
   att.put.nc(nc,variable,"oporig","NC_CHAR",obj...@oporig)
   callNextMethod(nc,variable,o)
}
)

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

Thanks to all.
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.petitho...@meteo.fr

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to