[R] Error in doc of corresp?

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Nov 12 12:30:15 CET 2001


On 12 Nov 2001, Peter Dalgaard BSA wrote:

> Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
>
> > On Mon, 12 Nov 2001, Agustin Lobo wrote:
> >
> > > I think that there is a problem in the doc
> > > of MASS function corresp:
> >
> > No, the problem is in R itself.  Remember MASS is a port from S code, and
> > this works as documented in S.  I am fairly sure it once worked in R too.
> >
> > Try calling corresp.matrix directly to work around an R bug.
> >
> > corresp is
> >
> > > corresp
> > function (x, ...)
> > {
> >     if (is.null(class(x)))
> >         class(x) <- data.class(x)
> >     UseMethod("corresp")
> > }
> >
> > That correctly sets the class of x to "matrix", but it then dispatches
> > corresp.default, even though corresp.matrix exists.
>
> Not sure this is a bug. Not a very useful feature either, though...
>
> It is as far as I can see behaving according to the documentation. To

Which documentation?  Not how I read ?UseMethod, and remember R uses
modified arguments in e.g. substitute where S does not.

> force dispatch based on the modified x , you could use
> UseMethod("corresp", x). As in
>
> > f.matrix <- function(x)print("matrix")
> > f <- function(x) {if(is.null(class(x))) class(x) <- data.class(x);UseMethod("f")}
> > m <- matrix(1:4,2)
> > f(m)
> Error in f(m) : no applicable method for "f"
> > f <- function(x) {if(is.null(class(x))) class(x) <- data.class(x);UseMethod("f",x)}
> > f(m)
> [1] "matrix"

That's not how S works, and it is not in the incompatibility list in the
FAQ.  If this is not regarded as bug then I think it needs to be mentioned
in both UseMethod.Rd and in the FAQ.

On the other hand, I see I once knew this: `S Programming' p.84.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list