[Rd] methods(class = class(<obj>)) - improve for |cl.| > 1 ?
Martin Maechler
m@echler @ending from @t@t@m@th@ethz@ch
Wed Oct 17 16:14:50 CEST 2018
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
More information about the R-devel
mailing list