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)
Like this: cut(rep(1L, 7), breaks = 3), but centered on 0 instead of 1.
Error in cut.default(rep(0L, 7), breaks = 3) : 'breaks' are not unique
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.
The behaviour does seem to conflict with the documentation, which says:
"If ‘x’ is a constant vector, equal-length intervals are created, one of
which includes the single value."
Created attachment 2376 [details]
Here's a patch
Created attachment 2377 [details]
Sorry, previous patch didn't have the abs()
Thank you, Joey Reid, for the good report that has been dusting away undeservedly,
and Benjamin for getting to it and propose the simple patch.
Fix committed to both R-devel (svn rev 75400) and R 3.5.1 patched