RcppCore/Rcpp — pull request #202 by yixuan (2014-11-19 22:12:08+00:00)
Title: add NAComparator for Rcomplex type

Hi All,
It seems that in the current version of Rcpp, member function `Vector::sort()` of `Vector` does not support complex vectors. This patch adds a comparator for the `Rcomplex` type, and it should work now. An example is given below:
```
> library(Rcpp)
> cppFunction('
+
+ RObject sort_complex(ComplexVector x)
+ {
+ ComplexVector xx = clone(x);
+ xx.sort();
+ return xx;
+ }
+
+ ')
>
> r = i = c(-1, 0, 1, NA, NaN)
> comb = expand.grid(r = r, i = i)
> s = complex(real = comb$r, imaginary = comb$i)
> sort(s, na.last = TRUE)
[1] -1- 1i -1+ 0i -1+ 1i 0- 1i 0+ 0i 0+ 1i 1- 1i 1+ 0i
[9] 1+ 1i NA NaN- 1i NA NaN+ 0i NA NaN+ 1i NA
[17] NA NA NA NA -1+NaNi 0+NaNi 1+NaNi NA
[25] NaN+NaNi
> sort_complex(s)
[1] -1- 1i -1+ 0i -1+ 1i 0- 1i 0+ 0i 0+ 1i 1- 1i 1+ 0i
[9] 1+ 1i NaN+NaNi NA 1+NaNi 0+NaNi -1+NaNi NA NA
[17] NA NA NA NaN+ 1i NA NA NaN- 1i NA
[25] NaN+ 0i
```

There are a few inconsistencies between the two versions of sorting, possibly due to different treatment of ties (involving missing values and NaN) in R and `std::sort()`.