[Rd] Can't make sort generic in quantile (S3)
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Aug 8 08:40:59 CEST 2006
On Tue, 8 Aug 2006, miguel manese wrote:
> Thanks for the fix. I'm guessing the rules are:
>
> a. a non S3 method is bound to the global env, and will see the def'n
> of an "S3-ized" method (e.g. I made is.list() generic and lapply, w/c
> is not generic, gets the S3-ized is.list)
> b. an S3 method implementation is bound to the namespace it was
> defined (w/c was the cause of my problem)
Please don't guess. The problem is not methods, but the generic.
When anything in package stats (in particular the quantile.default
method) calls sort, the search order is
namespace stats
namespace base
the search path starting at .GlobalEnv, including your package.
If sort were generic in base, then your S3 method would be found (and in
preference to a method of the same name in base).
So base:::sort always wins over anything you do.
> On 8/7/06, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> > It's a namepsace issue: any function in a namespace will see the
> > definition in base rather than yours.
> I'm not sure about this, because is.list above worked for me. Maybe
> this is just part of the rule?
>
> > quantile() is already generic, so why do you want to make sort() generic?
> > In particular, the function you show is not implementing much of the power
> > of sort (and in this case in particular not partial sorting).
> The vector (class sqlite.vector) to be sorted is a column in the
> database, and its sort is done by the db engine's sort whose result is
> written to another table. I was trying to implement quantile, but
> seeing that I was just copying the entire function (I never would have
> imagined that there are that many ways to compute quantiles), I
> experimented a bit and found out that it should be ok considering I
> have implemented sort() already.
>
>
> M. Manese
>
>
--
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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list