[R] S4 : setGeneric for classical methods

Martin Maechler maechler at stat.math.ethz.ch
Mon Jul 28 11:31:37 CEST 2008


>>>>> "CG" == Christophe Genolini <cgenolin at u-paris10.fr>
>>>>>     on Sun, 27 Jul 2008 09:27:34 +0200 writes:

    CG> Martin Maechler <maechler at stat.math.ethz.ch> a écrit :
    >>>>>>> "CG" == Christophe Genolini <cgenolin at u-paris10.fr>
    >>>>>>> on Sat, 26 Jul 2008 12:12:12 +0200 writes:
    >> 
    CG> Martin Maechler <maechler at stat.math.ethz.ch> a écrit :
    >> >>>>>>> "CG" == Christophe Genolini <cgenolin at u-paris10.fr>
    >> >>>>>>> on Tue, 22 Jul 2008 19:04:37 +0200 writes:
    >> >>
    CG> Prof Brian Ripley <ripley at stats.ox.ac.uk> a écrit :
    >> >> >> On Tue, 22 Jul 2008, cgenolin at u-paris10.fr wrote:
    >> >> >>
    >> >> >>> Hi the list (well, half of the list, only the one who
    >> >> >>> are not on holidays...)
    >> >> >>>
    >> >> >>> I am trying to make an S4 package. When I run it on a
    >> >> >>> console, everything seems ok. When I run R CMD check, I
    >> >> >>> got an error --- 8<
    >> >> >>> ----------------------
    >> >> >>> Error in setMethod("plot", "ClassX", function(x, y) { :
    >> >> >>> no existing definition for function "plot" --- 8<
    >> >> >>> ----------------------
    >> >> >>>
    >> >> >>> If I add
    >> >> >>> setGeneric("plot",function(x,y,...){standardGeneric("plot")})
    >> >> >>> in my code, then everything is OK.
    >> >> >>>
    >> >> >>> This is a surprise for me since I taught that we do not
    >> >> >>> need to redefine as generic the function that are
    >> >> >>> already generic, like "plot". Am I wrong ?
    >> >> >>
    >> >> >> Yes. And do read the error message.  It says
    >> >> >>
    >> >> >> no existing definition for function "plot"
    >> >> >>
    >> >> >> so this is not if the function is S3 or S4 generic, but
    >> >> >> that no such function is visible.
    >> >> >>
    >> >> >> Looks like you forgot to declare a dependence on (or
    >> >> >> import) package graphics.
    >> >>
    CG> I would have forgot if I knew that I have to declare
    CG> such a dependence...  Do we have to declare all the
    CG> depence to all the package ? To base ? To stats ?
    >> >>
    >> >> not to base, but to all other packages (since R can be loaded
    >> >> without any packages but base).
    >> >>
    CG> I thaught that the package that are include in R when we
    CG> start it had not to be include.
    >> >>
    >> >> You thought wrongly, and all our documentation mentions that you
    >> >> need to use 'Depends:' correctly (and  'Imports(..)' in
    >> >> NAMESPACE if you make use of one).
    >> >>
    >> >> {and please strongly note the correct spelling of "thought" !}
    >> >>
    >> >> Martin
    >> 
    CG> I correct DESCRIPTION and NAMESPACE adding Depends and import.
    CG> But I still get the message :
    >> 
    CG> checking for missing documentation entries ... WARNING
    CG> Undocumented S4 methods:
    CG> generic 'plot' and siglist 'ClassX'
    >> 
    CG> I can't find what is wrong...
    >> 
    >> well, it's  a message about *documentation*
    >> and therefore not related to DESCRIPTION
    >> and not much related to NAMESPACE.
    >> 
    >> It tells you that you don't have correct documentation for the
    >> plot method for ClassX.


    CG> What if I don't want to document this method? I did not put ClassX in 
    CG> the export, I do not want the user to acces to it.
    CG> I want :

    CG> plot,ClassX-method -> private
    CG> ClassY-class       -> public
    CG> plot,ClassY-method -> public

    CG> Is it possible ?

Yes, it is.
Excuse me not having read your previous posting in full detail.

So what you see is a warning in 'R CMD check' that is a so
called "false positive", i.e. warning in a case it should not.

Indeed, we have to acknowledge that the "R CMD check"ing code
in the context of "S4 + NAMESPACE" has not been perfect
recently... and the above is a good test case for improving the
"checking code".

BTW: I have recently started to look into using a few dummy
packages as part of the R-internal 'make check' checks.
Consequently, I'd be quite happy if you could provide (me or
R-devel) with the full   packS4_0.5.tar.gz  example package
{and maybe other versions of that}.

Merci, Christophe, for your perseverance!

Martin



    CG> Christophe

    --> "Writing R Extensions",
    >> section 2.1.3 'Documenting S4 classes and methods'
    >> 
    >> Regards,
    >> Martin
    >> 
    CG> ----- DESCRIPTION ----- Package: packS4
    CG> Type: Package
    CG> Title: Toy example of S4 package
    CG> Version: 0.5
    CG> Date: 2008-07-22
    CG> Author: Christophe Genolini / INSERM U669
    CG> Maintainer: <genolini at u-paris10.fr>
    CG> Description: Package built to illustration package 
    >> construction with S4
    CG> License: GPL (>=2)
    CG> LazyLoad: yes
    CG> Depends: methods, graphics
    CG> Collate: global.R ClassX.R ClassY.R ClassX-ClassY.R ClassZ.R
    >> 
    >> 
    CG> ------ NAMESPACE ------
    CG> export(
    CG> "classZ",
    CG> "functionClassicA"
    CG> )
    CG> exportMethods(
    CG> "getZ1",
    CG> "setZ1<-",
    CG> "publicA",
    CG> "plot"
    CG> )
    CG> exportClasses(
    CG> "ClassY",
    CG> "ClassZ"
    CG> )
    >> 
    CG> import(graphics)
    >> 
    CG> Christophe
    >> 
    >> 
    >> 
    >> 
    CG> ----------------------------------------------------------------
    CG> Ce message a ete envoye par IMP, grace a l'Universite Paris 10 
    >> Nanterre
    >> 
    >> 
    >> 

    CG> ______________________________________________
    CG> R-help at r-project.org mailing list
    CG> https://stat.ethz.ch/mailman/listinfo/r-help
    CG> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    CG> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list