[Rd] S4 package warning

Martin Maechler maechler at stat.math.ethz.ch
Fri Nov 12 11:14:26 CET 2010


>>>>> Robin Hankin <rksh1 at cam.ac.uk>
>>>>>     on Wed, 10 Nov 2010 09:53:30 +0000 writes:

    > Hello everyone.  R-2.12.0, suse linux 11.3.
    > I am debugging a package that uses S4 methods
    > and R CMD check gives the following warning:

    >> Warning in methods::findMethods(g, env) :
    >> non-generic function 'mdm' given to findMethods()
    >> See the information on DESCRIPTION files in the chapter 'Creating R
    >> packages' of the 'Writing R Extensions' manual.

    > I don't see anything obvious in that part of the R-exts but
    > FWIW, here is my DESCRIPTION file:

    >> Package: multivator
    >> Type: Package
    >> Title: A multivariate emulator
    >> Version: 1.0-1
    >> Depends: R(>= 2.10.0), emulator, methods, utils
    >> Date: 2009-10-27
    >> Author: Robin K. S. Hankin
    >> Maintainer:  <hankin.robin_nospamAT_gmail.com>
    >> Description: A multivariate generalization of the emulator package
    >> License: GPL-2
    >> LazyLoad: yes


    > I think that the lines in question in my package are:

    >> setClass("mdm", # "mdm" == "multivariate design matrix"
    >> representation = representation(
    >> xold  = "matrix",
    >> types = "factor"
    >> )
    >> )
    >> 
    >> 
    >> setGeneric("mdm",function(xold,types){standardGeneric("mdm")})
    >> setMethod("mdm",signature("matrix","factor"),function(xold, types){
    >> new("mdm", xold=xold, types=types)
    >> } )

    > which appear to execute without warning on a virgin console.  In the
    > package, there are three
    > or four other S4 classes which are on the same footing as the mdm class,
    > but do not appear to generate a warning from R CMD check.
    > The same happens AFAICS on R-2.13, 53543

    > Can anyone advise on how to deal with the warning?

It is probably simply the *order* of your R/*.R files which matters:
The setGeneric() has to come before all its setMethod()s.

A maintenance-intensive solution to the problem is to use a
'Collate:' field in your DESCRIPTION.
A much simpler approach is what we've done in the Matrix
package: use  R/AllClasses.R   and  R/AllGenerics.R
to put all setClass(.) and all setGeneric(.) calls,
respectively.
(and ensure not to use other file names that collate *before*
 'All*' in some locales).

Martin




    > thank you

    > Robin




    > -- 
    > Robin K. S. Hankin
    > Uncertainty Analyst
    > University of Cambridge
    > 19 Silver Street
    > Cambridge CB3 9EP
    > 01223-764877

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



More information about the R-devel mailing list