hughjonesd/santoku

`chop_n` can error out if there are too many non-unique values

hughjonesd opened this issue · 0 comments

Example:

chop_n(c(1,2,5,5,5), 2)
## Error in create_breaks(obj, left_vec) : 
##  breaks contained more than two consecutive equal values

In a way that's reasonable, because you can't create breaks satisfying the size <= n constraint here. But it violates the "don't error on data" principle. It would be better to warn and carry on.

A related problem which isn't quite a bug: small groups in the middle of the data.

tab_n(c(1,2,4,5,5), 2)
## [1, 4) [4, 5)    {5} 
##     2      1      2 

This is a side effect of the code creating a singleton interval (because 2 exactly divides 5-1). It's not ruled out by the documentation, which simply says "one interval may have fewer elements",
but it seems unpredictable. Then again, what else could you do here?