[Rd] Improvement of R_orderVector() via orderVector1()

Marius Hofert marius.hofert at uwaterloo.ca
Fri Oct 9 13:53:41 CEST 2015


Hi,

I think R_orderVector() can be improved by calling orderVector1() if
possible. In a problem we had, this gave us a run time improvement
factor of 4.... so my hope is that this can be included. Below is the
suggested change, I'm just not 100% sure if the test "CDR(arglist) ==
R_NilValue" is good...

Cheers,
Marius

void R_orderVector(int *indx, // must be pre-allocated to length >= n
                   int n,
                   SEXP arglist, // <- e.g.  Rf_lang2(x,y)
                   Rboolean nalast, Rboolean decreasing)
{
    // idx[] <- 0:(n-1) :
    for(int i = 0; i < n; i++) indx[i] = i;
    if(CDR(arglist) == R_NilValue) {
        orderVector1(indx, n, CAR(arglist), nalast, decreasing, R_NilValue);
    } else {
        orderVector(indx, n, arglist, nalast, decreasing, listgreater);
    }
    return;
}



More information about the R-devel mailing list