[Rd] Suggestion: add a warning in the help-file of unique()

Matthieu Stigler stigler3 at etu.unige.ch
Thu Apr 17 12:44:32 CEST 2008


Hello

I'm sorry if this suggestion/correction was already made but after a 
search in devel list I did not find any mention of it.
I would just suggest to add a warning or an exemple for the help-file of 
the function unique() like

"Note that unique() compares only identical values. Values which, are 
printed equally but in facts are not identical will be treated as 
different."


 > a<-c(0.2, 0.3, 0.2, 0.4-0.1)
 > a
[1] 0.2 0.3 0.2 0.3
 > unique(a)
[1] 0.2 0.3 0.3
 >

Well this is just the idea and the sentence could be made better (my 
poor english...). Maybe a reference to RFAQ 7.31 could be made.
Maybe is this behaviour clear and logical for experienced users,  but I 
don't think it is for beginners. I personnaly spent two hours to see 
that the problem in my code came from this.

I was thinking about modify the function unique() to introduce a "tol" 
argument which allows to compare with a tolerance level (with default 
value zero to keep unique consistent) like all.equal(), but it seemed 
too complicated with my little understanding.

Bests regards and many thanks for what you do for R!

Matthieu Stigler



More information about the R-devel mailing list