[Rd] RCMD CHECK and non-methods

Martin Maechler maechler at stat.math.ethz.ch
Thu Aug 26 17:36:22 CEST 2010


>>>>>   <Mark.Bravington at csiro.au>
>>>>>     on Wed, 25 Aug 2010 14:06:07 +1000 writes:

    > I recently moved a function 'subset.with.warning' into the 'mvbutils' package (a version not yet on CRAN). When I tried RCMD CHECK, I got this warning:
    > * checking S3 generic/method consistency ... WARNING
    > subset:
    > function(x, ...)
    > subset.with.warning:
    > function(x, cond, mess.head, mess.cond, row.info, sub)

    > See section 'Generic functions and methods' of the 'Writing R Extensions'
    > manual.

    > I know that S3 method arguments need to be compatible with arguments of the generic. However, 'subset.with.warning' is deliberately not a registered S3 method, 

I think that's your real trouble ... and then your users' if you
really insist.
Short answer:  "Don't do that!"

There have been a few exceptions of "100 years old" R functions
which validated this rule,
the most notable probably  t() and t.test(),
and we (R core) have explicitly listed them in the code base
as "yes, looks like a method for an S3 generic, but not it ain't!",
but have basically "forbidden" to commit more such crimes.
{Also, if you are interested: I think both  t() and t.test()
 pre-dated S3}


    > and its USAGE section doesn't include a \method{generic}{class} statement. I couldn't see anything in "R Extensions" that says "don't do this", so I'm wondering: 

Yes, we should add a such "don't do this" somewhere.

Can you propose a good place to put it in there?

    > - should this really be a NOTE not a WARNING (or nothing at all)?

{from the above: definitely a warning, if not "worse"}....

Best regards,
Martin 

Martin Maechler, ETH Zurich

    > - if not, shouldn't there be a more explicit statement to the effect that "if R decides it's a method, then it damned well is a method, whether you think it is or not"?

    > - and if so, should there also be a check for functions that look like methods but aren't registered and declared as such?

    > My preference would be for the first, FWIW. Admittedly, just because I didn't register 'subset.with.warning' as an S3 method, that won't stop 'subset' from trying to use it if it ever encounters an object of class "with.warning". It's a risk that I'm happy to take, though CRAN might not be...

    > I made the warning go away by adding a '...' argument to the end of 'subset.with.warning', but that's not pretty.

    > Mark Bravington
    > CSIRO
    > Hobart
    > Australia

    >> sessionInfo()
    > R version 2.11.1 Patched (2010-06-30 r52418) 
    > i386-pc-mingw32 

    > locale:
    > [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
    > [5] LC_TIME=English_Australia.1252    

    > attached base packages:
    > [1] grDevices tools     tcltk     stats     graphics  utils     methods   base     

    > other attached packages:
    > [1] ad_1.0         chstuff_1.0    handy2_1.2     tweedie_2.0.2  statmod_1.4.1  handy_1.1      debug_1.2.3    mvbutils_2.5.2
    >> 

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



More information about the R-devel mailing list