Skip to content

On base::rank

3 messages · Martin Maechler, Arunkumar Srinivasan

#
Have a look at the following, taken from base::rank:

...
    if (!is.na(na.last) && any(nas)) {
        yy <- integer(length(x)) # <~~~~~~~~~
        storage.mode(yy) <- storage.mode(y) # <~~~~~~~~
        yy <- NA
        NAkeep <- (na.last == "keep")
        if (NAkeep || na.last) {
            yy[!nas] <- y
            if (!NAkeep)
                yy[nas] <- (length(y) + 1L):length(yy)
        }
...

Alternatively, look at lines 36 and 37 here:
https://github.com/wch/r-source/blob/fbf5cdf29d923395b537a9893f46af1aa75e38f3/src/library/base/R/rank.R#L36

There seems to be no need for those lines, IIUC. Isn't it? 'yy' is
replaced with NA in the ver next line.

Best,
Arun.
#
Indeed.   Interesting that nobody has noticed till now,
even though that part has been world readable since at least 2008-08-25.

Note that the R source code is at 
     http://svn.r-project.org/R/
and the file in question at
     http://svn.r-project.org/R/trunk/src/library/base/R/rank.R

where you can already see the new code
(given that 'x' was no longer needed, there's no need for 'xx').

Martin Maechler, 
ETH Zurich
#
That was what made me a bit unsure :-).
Okay, thanks.
Great! thanks again.
Best,
Arun.