[Rd] exporting s3 and s4 methods

John Chambers jmc at r-project.org
Tue Mar 17 17:41:57 CET 2009


You shouldn't have to export the S3 function:  in the normal practice, 
setGeneric("biglm") or just a setMethod("biglm", ....) will cause the S3 
function (like any existing function) to become the default method for 
the S4 generic.  There is only one object called "biglm".

It's important though to use the default, one argument, call to 
setGeneric().  Otherwise the two functions are not consistent and can't 
exist in the same namespace.  Also, the situation is different if the S3 
function is in another package, as discussed in a previous thread here 
recently.

The warning messages below, if they are still current, are misleading, 
and usually outright wrong.  The code should look at the default method 
for the S4 generic.

John

PS: if this is the biglm() in the biglm package, the current CRAN 
version is not a generic of any flavor.  Presumably this is a new 
version?  Just curious, this has no effect on the above comments.

Thomas Lumley wrote:
>
> If a package defined an S3 generic and an S4 generic for the same 
> function (so as to add methods for S4 classes to the existing code), 
> how do I set up the namespace to have them exported?
>
> With import(stats)
> exportMethods(bigglm)
> importClassesFrom(DBI)
> useDynLib(biglm)
> export(biglm)
> export(bigglm)
> in NAMESPACE, the S3 generic is not exported.
>> methods("bigglm")
> [1] bigglm.RODBC*      bigglm.data.frame* bigglm.function*
>
>    Non-visible functions are asterisked
> Warning messages:
> 1: In findGeneric(generic.function, parent.frame()) :
>   'bigglm' is a formal generic function; S3 methods will not likely be 
> found
> 2: In methods("bigglm") : function 'bigglm' appears not to be generic
>
>
> [This is R 2.7.2, admittedly a little ancient]
>
>       -thomas
>
> Thomas Lumley            Assoc. Professor, Biostatistics
> tlumley at u.washington.edu    University of Washington, Seattle
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list