[Rd] sort(list(..)) ?

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 27 Mar 2001 18:05:51 +0200


Looking at the source code of  sort()
-- for some speedup considerations --
I found that we currently use isVector() for testing the validity of x in
sort(x) whereas I think we should use isVectorAtomic(),
actually for S-plus compatibility additionally allowing NULL.
Hence I'd propose to replace
the test

    if (!isVector(CAR(args)))
	errorcall(call, "only vectors can be sorted");

by

    if(CAR(args) == R_NilValue) return R_NilValue;
    if(!isVectorAtomic(CAR(args)))
	errorcall(call, "only atomic vectors can be sorted");

in do_sort(.) in src/main/sort.c .
This doesn't quite pass "make check" currently because

  is.factor(factor(list()))

now would give an error.

I still think we should not silently allow list()s {or expression()s} as
argument to sort() as we do now; BTW, we just return them unchanged.

We could produce a warning instead of an error 
which would be more back-compatible, but I'd prefer the error.

Opinions?
{no feedback will be interpreted as:  
    "agreed, go ahead and change for R 1.3.0"}

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._