[Rd] Specifying a function as not being and S3 Class function

S Ellison S.Ellison at LGCGroup.com
Tue Apr 24 18:50:15 CEST 2012


> Is it possible to  keep from triggering the following warning 
> when I check the package? 
>
> summary:
>   function(object, ...)
> summary.agriculture:
>   function(x, analyte.names, results.col, analyte.col, by, det.col,
> [clip]

Part of the solution is to add ... to the legacy function; that is required by the generic and is missing in your own function. Adding ... will not break existing code.

The name of the initial argument will still cause problems. But I've kludged round a similar issue (an intentional difference in required parameters, in my case) by replacing something like

obj.summary(x, y, z, ...) 

with something like
obj.summary(object, y, z, x=object, ...)

This preserves legacy argument order, is consistent with summary(object, ...) and retains the named argument x to avoid code changes. 

But it is clearly a kludge. It also runs the risk of accidental overwriting of x if someone specifies too many unnamed parameters. That should not happen in working legacy code, of course, as that would have broken if you included a surplus parameter in a function call with no ... . If it _is_ a problem you could try obj.summary(object, y, z, ..., x=object), which would avoid the accidental assignment by requiring exact match naming, but I cannot recall offhand if that construct would be considered consistent with the generic using the current CMD check. 

Steve Ellison

> -----Original Message-----
> From: r-devel-bounces at r-project.org 
> [mailto:r-devel-bounces at r-project.org] On Behalf Of Matt Pocernich
> Sent: 24 April 2012 16:34
> To: r-devel at r-project.org
> Subject: [Rd] Specifying a function as not being and S3 Class function
> 
> 
> I am compiling a library with legacy code which has functions 
> named with periods in the names - but are not S3 class 
> functions.    For example for example,  summary.agriculture 
> is not an extension of the summary function for and 
> 'agriculture. class object - it is just poorly named.  
> 
> Is it possible to  keep from triggering the following warning 
> when I check the package? 
> 
> * checking S3 generic/method consistency ... WARNING
> 
> summary:
>   function(object, ...)
> summary.agriculture:
>   function(x, analyte.names, results.col, analyte.col, by, det.col,
>            iQuantiles, iDetStats, iSW, iUCL, iLand, conf.level, iUTL,
>            tol.level, utl.conf.level, iND, sig.figs)
> 
> I know that the best answer would be to rename with a better 
> naming convention, but that would cause issues with legacy 
> applications.
> 
> Thanks,
> 
> Matt
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> *******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-devel mailing list