waldo
waldo copied to clipboard
Comparison of fractional values might not be guessing enough digits
i.e. this was somewhat confusing:
waldo::compare(-0.9090909, 0.9090909)
#> `old`: -1
#> `new`: 1
Reminder to look into scales::precision
to see if it has any better logic
Technically, this is correct behaviour because 0 digits are sufficient to distinguish these two numbers (-1 and 1 are different). So I'm not sure how to adapt the general rule to make the behaviour more appealing.
Oh I see how it is working now and I see how we get the current output. It seems ok to keep as is now that I understand it a bit more
For what it's worth, I ended up finding this issue for the same "this is somewhat confusing" reasons, because:
# waldo 0.5.1
waldo::compare(-0.5, 0.5)
## `old`: -0
## `new`: 0
In my usage case, I was modifying a series of deeply nested lists and double checking the new objects. compare()
's output made me take several minutes to drill down in the affected lists to check the relevant elements, because I was puzzled as to how I'd potentially lost storage precision, given the modifications I'd made.
If it's intended behavior, per Hadley's explanation above, (shrug) OK. That said: reporting a single place after the decimal to get a non-zero digit might help. I recognize that might go against general waldo
(and/or tidyverse
[?]) style principles, though, which I'm admittedly not deeply familiar with.
Maybe one alternative is to not round at all, and instead add a grey coloring to the non-important digits?
# original example
-<grey>0.9090909</grey>
<grey>0.9090909</grey>
# more realistic
-0.91<grey>90909</grey>
-0.90<grey>909</grey>
Or maybe we should always just show one more digit than absolutely necessary?
That would work, as the default (clearly). If I were benevolent ruler for a day, though, I'd also want an option where, by setting it, I could enable Davis' proposed alternative.
To offer more data by way of my use case, I was setting parameter values for a slew of Monte Carlo simulation runs. All the stored digits were relevant and meaningful (vs. real data or estimates, where additional digits might give the illusion of meaning or precision in unhelpful ways).
waldo
having the ability to gray out all digits after the first meaningful difference, but still reporting those digits, would be the best of both worlds, for me: waldo
's printed formatting makes it clear where the difference arises, but it's also clear what the stored values are, to spot check storage precision.
However, I recognize I am not benevolent ruler for a day. This might just be a situation where I'd have to implement the checks I was making in another way.