Skip to content

Breaks deal with ranges more consistently#519

Open
teunbrand wants to merge 4 commits into
r-lib:mainfrom
teunbrand:safe_break_ranges
Open

Breaks deal with ranges more consistently#519
teunbrand wants to merge 4 commits into
r-lib:mainfrom
teunbrand:safe_break_ranges

Conversation

@teunbrand
Copy link
Copy Markdown
Contributor

This PR aims to fix #518.

Briefly:

  • We always call range() on the input to deal with length >2 data.
  • Non-finites are always removed from the range.
  • Length 0 in, length 0 out.
  • Length 1 or zero-range in, first element out

Reprex from issue:

devtools::load_all("~/packages/scales/")
#> ℹ Loading scales

good <- c(1, 20)
bad <- c(1, 10, 20)

scales::breaks_extended(n=5)(good)
#> [1]  0  5 10 15 20
scales::breaks_extended(n=5)(bad)
#> [1]  0  5 10 15 20

scales::breaks_width(width=5)(good)
#> [1]  0  5 10 15 20
scales::breaks_width(width=5)(bad)
#> [1]  0  5 10 15 20

scales::breaks_exp(n = 5)(good)
#> [1] 20 19 18 17  0
scales::breaks_exp(n = 5)(bad)
#> [1] 20 19 18 17  0

scales::breaks_log(n = 5)(good)
#> [1]  1  3 10 30
scales::breaks_log(n = 5)(bad)
#> [1]  1  3 10 30

scales::breaks_pretty(n=5)(good)
#> [1]  0  5 10 15 20
scales::breaks_pretty(n=5)(bad)
#> [1]  0  5 10 15 20

scales::breaks_timespan(unit = "mins")(good)
#> Time differences in secs
#> [1]    0  240  480  720  960 1200
scales::breaks_timespan(unit = "mins")(bad)
#> Time differences in secs
#> [1]    0  240  480  720  960 1200

Created on 2025-11-13 with reprex v2.1.1

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.

Vague documentation or incorrect behaviour in the breaks_* functions

1 participant