Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zero_range() casts to numeric #469

Merged
merged 2 commits into from
Oct 22, 2024
Merged

zero_range() casts to numeric #469

merged 2 commits into from
Oct 22, 2024

Conversation

teunbrand
Copy link
Contributor

This PR aims to fix #468 and by extension fix tidyverse/ggplot2#6134.

Briefly, we cast input x to numeric before doing computations for the range.

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

range <- structure(c(1234, 7380), class = "difftime", units = "secs")

zero_range(range)
#> [1] FALSE

ggplot2::resolution(range, zero = FALSE)
#> [1] 6146

Created on 2024-10-11 with reprex v2.1.1

# If we reach this, then x must be (-Inf, Inf) or (Inf, -Inf)
if (all(is.infinite(x))) {
# If we reach this, then x must be (-Inf, <number>) or (<number>, Inf)
if (any(is.infinite(x))) {
Copy link
Contributor Author

@teunbrand teunbrand Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if just 1 of the 2 numbers are infinite we have non-zero range. (same-sign infinites are handled above)

@thomasp85 thomasp85 merged commit 90c8792 into r-lib:main Oct 22, 2024
12 checks passed
@teunbrand teunbrand deleted the zero_range branch October 22, 2024 07:55
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.

Zero Range for HMS object Resolution on an hms object
2 participants