I am not sure if this is a documentation problem or an implementation
problem:

The 'partial' feature of sort works fine with all values of na.last for some
values of 'partial':

> sort(c(3,NA,1,2),na.last=FALSE,partial=1:2)     # find minimum values
[1] NA  1  2  3
> sort(c(3,NA,1,2),na.last=TRUE,partial=1:2)
[1]  1  2  3 NA
> sort(c(3,NA,1,2),na.last=NA,partial=1:2)
[1] 1 2 3

> sort(c(3,NA,1,2),na.last=FALSE,partial=2:3)
[1] NA  1  2  3
> sort(c(3,NA,1,2),na.last=TRUE,partial=2:3)
[1]  1  2  3 NA
> sort(c(3,NA,1,2),na.last=NA,partial=2:3)
[1] 1 2 3

but not all:

> sort(c(3,NA,1,2),na.last=FALSE,partial=3:4)     # find maximum values
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
  index 4 outside bounds
> sort(c(3,NA,1,2),na.last=TRUE,partial=3:4)
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
  index 4 outside bounds
> sort(c(3,NA,1,2),na.last=NA,partial=3:4)
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
  index 4 outside bounds                         # error is expected here,
since there will be no .[4] value

Thought the documentation warns that "many of the options are not available
for partial sorting", it does not seem to say anything about NA not being
handled in some cases.

The problem seems to occur when the 'partial' range would have included
non-existent positions if na.last were NA, even when na.last is not NA.

           -s

	[[alternative HTML version deleted]]

