Bug 16802

Summary: Cut breaks are not unique if all(x == 0)
Product: R Reporter: joey reid <joey.reid+bugzillaR>
Component: MiscAssignee: R-core <R-core>
Status: UNCONFIRMED ---    
Severity: normal    
Priority: P5    
Version: R 3.2.4   
Hardware: x86_64/x64/amd64 (64-bit)   
OS: OS X Yosemite   

Description joey reid 2016-04-07 14:00:49 UTC
Cut uses the magnitude of the only unique value to set the sequence steps size for calculating breaks. This results in no unique breaks when that only unique value of x is 0.

*Steps to reproduce*
cut(rep(0L, 7), breaks = 3)

*Expected outcome*
Like this: cut(rep(1L, 7), breaks = 3), but centered on 0 instead of 1.

*Actual Results*
Error in cut.default(rep(0L, 7), breaks = 3) : 'breaks' are not unique

*Additional Info*
The problem is that when the range of the data is zero, cut defines a sequence using the minimum of the data as the base for the step size. 

dx <- abs(rx[1L])
breaks <- seq.int(rx[1L] - dx/1000, rx[2L] + dx/1000, length.out = nb)

Since dx = 0 when all(x == 0) the breaks will never be unique. It seems like there's no need to base the step size on the magnitude of the only value in x, just using 1/1000 would be sufficient.