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

updating precision in round2() #1496

Merged
merged 10 commits into from
Apr 24, 2023
Merged

updating precision in round2() #1496

merged 10 commits into from
Apr 24, 2023

Conversation

ddsjoberg
Copy link
Owner

@ddsjoberg ddsjoberg commented Apr 17, 2023

What changes are proposed in this pull request?

If there is an GitHub issue associated with this pull request, please provide link.
closes #1494
closes #1472


Reviewer Checklist (if item does not apply, mark is as complete)

  • Ensure all package dependencies are installed by running renv::install()
  • PR branch has pulled the most recent updates from master branch. Ensure the pull request branch and your local version match and both have the latest updates from the master branch.
  • If an update was made to tbl_summary(), was the same change implemented for tbl_svysummary()?
  • If a new function was added, function included in _pkgdown.yml
  • If a bug was fixed, a unit test was added for the bug check
  • Run pkgdown::build_site(). Check the R console for errors, and review the rendered website.
  • Code coverage is suitable for any new functions/features. Review coverage with withr::with_envvar(new = c("NOT_CRAN" = "true"), covr::report()). Begin in a fresh R session without any packages loaded.
  • R CMD Check runs without errors, warnings, and notes
  • usethis::use_spell_check() runs with no spelling errors in documentation

When the branch is ready to be merged into master:

  • Update NEWS.md with the changes from this pull request under the heading "# gtsummary (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • Increment the version number using usethis::use_version(which = "dev")
  • Run codemetar::write_codemeta()
  • Run usethis::use_spell_check() again
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge".

@nikostr
Copy link

nikostr commented Apr 18, 2023

Thanks for looking into this! Won't this implementation simply shift where problems occur? Running

number <- 10^seq(1,15)
(number + sqrt(.Machine$double.eps)) == number
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
round2(2.5e10, digits=-10)
#> [1] 2e+10

and since sqrt(.Machine$double.eps) is about 1.5e-8 any numbers in that range will start behaving badly.

Very frustrating that this isn't something that just works in R!

@ddsjoberg
Copy link
Owner Author

@nikostr oh yes, i was just in the middle of testing out a few things. I was hoping to land on a solution that had fewer computations....but as you noted, the previous code wasn't perfect.

I've tested the janitor/stackoverflow solution too, and it's better, but has some issue too round2(0.499999999, digits = 0) = 1 ¯_(ツ)_/¯

@ddsjoberg ddsjoberg marked this pull request as ready for review April 24, 2023 00:34
@ddsjoberg ddsjoberg merged commit 1a13caf into main Apr 24, 2023
@ddsjoberg ddsjoberg deleted the gah-round2 branch April 24, 2023 01:07
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.

Bug Report: round2 is unreliable Remove dplyr::storms from unit testing
2 participants