Thanks to both Martins, your advice solved the confusion between S3 and S4
classes for the show method.

br.
Leo

On Tue, Jul 21, 2009 at 9:58 AM, Martin Maechler <maech...@stat.math.ethz.ch
> wrote:

> >>>>> "MartinMo" == Martin Morgan <mtmor...@fhcrc.org>
> >>>>>     on Mon, 20 Jul 2009 18:57:33 -0700 writes:
>
>    MartinMo> L L <lmla...@gmail.com> writes:
>    >> Ok, I could solve also the latter problem by defining show.myclass
> function in
>    >> the zzz.R file and adding the line 'S3method(show,myclass)' into
> NAMESPACE
>    >> file. Now the package passes all checks.
>
>     MartinMo> I would have, in NAMESPACE,
>
>    MartinMo> importFrom(methods, show)
>    MartinMo> exportMethods(show)
>
>    MartinMo> and in some file in R/
>
>    MartinMo> setMethod(show, "myclass", function(object) {
>    MartinMo> cat("here I am\n")
>    MartinMo> })
>
>    MartinMo> Do not try to make an S3 method on an S4 generic,
>    MartinMo> or to create a new S4 generic for show. Since
>    MartinMo> you've defined a method on show, you need to add
>    MartinMo> documentation in a file in man/ (your choice; I'd
>    MartinMo> add the documentation to the myclass documentation
>    MartinMo> page). You only get one
>    MartinMo> \alias{show,myclass-method}.
>
>    MartinMo> Martin
>
> Yes, indeed!
> I'm just ``signing''  Martin Morgan's very good advice.
>
> In case it was explicit enough:
> do *NOT* define  show.myclass()  [which is an S3 method for an
>                                  S4 generic and S4 class ..]
>
> Martin Mächler
>
>
>    >> The information on how to exactly extend existing methods and include
> new
>    >> methods/classes into a package is available but rather scattered in
> the web. A
>    >> step-by-step tutorial written by an experienced user who is aware of
> best
>    >> practices etc. would be rather useful for a beginner.
>    >> best regards
>    >> Leo
>    >>
>    >>
>    >> On Mon, Jul 20, 2009 at 7:09 PM, L L <[[lmla...@gmail.com]]> wrote:
>    >>
>    >> Thanks, the issue was solved by adding class definitions to the
>    >> zzz.R file in the R code directory. However, this led to a new
>    >> problem.
>    >> The zzz.R now contains class definition:
>    >> > setClass("myclass", contains = "list")
>    >> and  method definition for the new class, extending the generic
>    >> show':
>    >> > setGeneric("show",function(x,...){standardGeneric("show")})     >
>    >> setMethod("show", "myclass",function(x, ...) {cat("myclass object
>    >> \n")})
>    >> I get two warnings. The first one:
>    >> * checking Rd files ... WARNING     Rd files with duplicated alias
>    >> show,myclass-method':       myclass-class.Rd show-methods.Rd
>    >> I get this one because the alias row for the method
>    >> (\alias{show,myclass-method}) is in both myclass-class.Rd file and
>    >> show-methods.Rd file (created by promptMethods function). This is
>    >> likely related to the second warning:
>    >> * checking for missing documentation entries ... WARNING
> Undocumented
>    >> code objects:       show
>    >> I thought that the show method would've been documented correctly as
>    >> I put 'show-methods.Rd' file in the 'man' directory. This does not
>    >> seem to be the case, however.
>    >> Any help on how I should document the extended show method in this
>    >> case, or are there some mistakes in my original definition for
>    >> extended 'show'? I could not find suitable examples from the
>    >> web/mailing lists.
>    >> br     Leo
>
>

        [[alternative HTML version deleted]]

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

Reply via email to