From becker@g@be @ending from gene@com  Fri Oct 19 20:55:40 2018
From: becker@g@be @ending from gene@com (Gabe Becker)
Date: Fri, 19 Oct 2018 11:55:40 -0700
Subject: [Rd] methods(class = class(<obj>)) - improve for |cl.| > 1 ?
In-Reply-To: <CAJXgQP09AcUn4Jm=gjeQeCUokLigtk+WGM46Kv_y1yteAvW6qQ@mail.gmail.com>
References: <23495.17370.834231.288292@stat.math.ethz.ch>
 <CAJXgQP09AcUn4Jm=gjeQeCUokLigtk+WGM46Kv_y1yteAvW6qQ@mail.gmail.com>
Message-ID: <CAMFmJs=E9VytRLSkuRBrUYuHV8+VfgapP8Tm8mo1xZJ4WmCGqg@mail.gmail.com>

Martin and Kevin,

Perhaps a variant of methods which more directly addresses the use-case
Kevin mentions might be in order?

I am happy to prepare a patch which implements a methodsForObj function
(name very much negotiable), or a third obj argument to methods which takes
the actual object and answers the question "what methods would I hit for an
object just like this one?" directly. Is this something you (Martin, et al
in R core), are interested in and would consider?

I know people can always do methods(class = class(obj)) after the change
being discussed (and contingent on that change what I described could be
trivially implemented that way), but  should they need to?

Best,
~G



On Fri, Oct 19, 2018 at 10:55 AM, Kevin Ushey <kevinushey at gmail.com> wrote:

> I think this would be a good change. I think most users use the
> 'methods(class = <...>)' function to answer the question, "what
> methods can I call on objects with these classes?", and in that
> context I think it would be sensible for the function to accept more
> than one class.
>
> Kevin
>
> On Wed, Oct 17, 2018 at 7:15 AM Martin Maechler
> <maechler at stat.math.ethz.ch> wrote:
> >
> > With new "strict" settings in R-devel, the following glm() example
> >
> > > data(anorexia, package = "MASS")
> > > fm <- glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian,
> data = anorexia)
> > > methods(class = class(fm))
> > Warning in grep(name, row.names(info)) :
> >   argument 'pattern' has length > 1 and only the first element will be
> used
> > Warning in gsub(name, "", row.names(info)) :
> >   argument 'pattern' has length > 1 and only the first element will be
> used
> > Warning in grep(pattern, all.names, value = TRUE) :
> >   argument 'pattern' has length > 1 and only the first element will be
> used
> > Warning in grep(pattern, all.names, value = TRUE) :
> >   argument 'pattern' has length > 1 and only the first element will be
> used
> > ...........
> > ...........
> > ...........
> > [ca. 20 lines of warnings]
> >
> > and then shows the "glm" methods, but not "lm" ones.
> >
> > This is not a bug strictly, as  ?methods says that
> >
> >    class: a symbol or character string naming a class: only used if
> >           ?generic.function? is not supplied.
> >
> > and so the use of
> >
> >            methods(class = class(<obj>))
> >
> > is a user error when  class(<obj>)  is of length > 1.
> >
> > In the case of e.g. a randomForest() result, we also get 25
> > warnings, i.e. 50 lines, but then
> >
> > --->>>  no methods found
> >
> > because
> >
> >    > class(rf.fit)
> >    [1] "randomForest.formula" "randomForest"
> >
> > and no methods are  defined for "randomForest.formula".
> >
> > ---
> >
> > Of course, all this works fine with S4 classes:  There the full
> > inheritance is used and all methods are found.
> >
> > Still, would it make sense to improve the underlying .S3methods() ?
> >
> > I assume it will break *some* overzealous package checks out
> > there when .S3methods() and hence methods() would return *more*
> > in such case.
> >
> > Comments?
> >
> > --
> > Martin Maechler
> > ETH Zurich  and  R Core
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Gabriel Becker, Ph.D
Scientist
Bioinformatics and Computational Biology
Genentech Research

	[[alternative HTML version deleted]]



[Rd] methods(class = class(<obj>)) - improve for |cl.| > 1 ?
Gabe Becker