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

Add better handling for large numbers in is.integerish #47

Merged
merged 1 commit into from
Jun 26, 2018
Merged

Add better handling for large numbers in is.integerish #47

merged 1 commit into from
Jun 26, 2018

Conversation

jameslamb
Copy link
Contributor

This PR addresses concerns raised in #42 and #44 . Basically, is.integerish encounters NAs when you try to apply it over values that are larger than base::.Machine$integer.max. In this PR, I just added explicit handling for that condition to throw a more informative error message.

@hadley
Copy link
Owner

hadley commented Jun 25, 2018

Wouldn't it be simpler to do is.integer(x) || (is.numeric(x) && all(x == trunc(x))) ?

@jameslamb
Copy link
Contributor Author

@hadley good suggestion, I've implemented it. Had never heard of trunc() before.

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@a042cde). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #47   +/-   ##
=========================================
  Coverage          ?   73.25%           
=========================================
  Files             ?        9           
  Lines             ?       86           
  Branches          ?        0           
=========================================
  Hits              ?       63           
  Misses            ?       23           
  Partials          ?        0
Impacted Files Coverage Δ
R/assertions.r 94.11% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a042cde...dfa2f54. Read the comment docs.

is.integer(x) || (is.numeric(x) && all(x == as.integer(x)))

# using trunc() to deal with very large numbers (including Inf)
res <- is.integer(x) || (is.numeric(x) && all(x == trunc(x)))
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please eliminate the explicit return? See http://style.tidyverse.org/functions.html#return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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.

3 participants