r-quantities / units

Measurement units for R
https://r-quantities.github.io/units
175 stars 28 forks source link

hist fails when breaks get fuzzy... #368

Closed barryrowlingson closed 6 months ago

barryrowlingson commented 6 months ago

I get an error when histogramming a vector with units in very particular cases - a short vector with some "edge case" values, seems to be related to finding the breaks... I think its because its triggering "fuzz" in the breakpoints and the fuzz parameter isn't unitted:

library(units)
# two numbers near 1, two near 0...
x2u = c(rep(0.0001,2), rep(0.999,2))
# keep this for later
x2 = x2u
# add units to x2u
units(x2u) = "m"
# un-unitted version histograms okay
hist(x2)
# unitted version fails:
hist(x2u)
# Error in Ops.units(breaks, fuzz) : 
 #  both operands of the expression should be "units" objects
packageVersion("units")
[1] ‘0.8.5’

I tried passing a unitted fuzz parameter but that breaks hist.default elsewhere in a comparison between the fuzz and zero:

> hist(x2u, fuzz=fuzz)
Error in Ops.units(fuzz, 0) : 
  both operands of the expression should be "units" objects
edzer commented 6 months ago

Thanks @barryrowlingson !