Skip to content

Adjust auto accuracy heuristic#304

Merged
hadley merged 3 commits intor-lib:mainfrom
davidchall:reduce-precision
Mar 16, 2022
Merged

Adjust auto accuracy heuristic#304
hadley merged 3 commits intor-lib:mainfrom
davidchall:reduce-precision

Conversation

@davidchall
Copy link
Contributor

@davidchall davidchall commented Mar 27, 2021

Fixes #279

The auto accuracy heuristic shows 2 significant figures, relative to the smallest difference between breaks. This is designed to handle situations like (taken from tidyverse blog post):

However, this heuristic displays an unnecessary digit in the specific case when all the breaks align with zeros in the final digit. This situation naturally occurs very often. Here's an example (taken from the scales docs):

image

This PR reduces the precision when final digit is always zero.

Before

library(scales)

number(seq(0, 0.1, 0.025))
#> [1] "0.000" "0.025" "0.050" "0.075" "0.100"
number(seq(0, 20, 5))
#> [1] "0.0"  "5.0"  "10.0" "15.0" "20.0"

Created on 2021-03-27 by the reprex package (v1.0.0)

After

library(scales)

number(seq(0, 0.1, 0.025))
#> [1] "0.000" "0.025" "0.050" "0.075" "0.100"
number(seq(0, 20, 5))
#> [1] "0"  "5"  "10" "15" "20"

Created on 2021-03-27 by the reprex package (v1.0.0)

Reduce precision when 2nd significant figure is always zero
@hadley hadley merged commit cc83905 into r-lib:main Mar 16, 2022
@hadley
Copy link
Member

hadley commented Mar 16, 2022

Thanks! This is a great little improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

number(accuracy = NULL) heuristic too precise?

2 participants