Rounding Infrastructure

Flexible rounding functions for use in error detection. They were outsourced from the 'scrutiny' package.


roundwork

R-CMD-check

The goal of roundwork is to enable flexible rounding beyond base::round(). Its main API is reround(), from which all implemented rounding procedures can be accessed. This is useful to reconstruct how others may have rounded their data.

Given a rounded number, call unround() to get the lower and upper bounds of the original number. This also takes rounding options into account, just like reround() does.

Many roundwork functions used to be part of scrutiny. They were outsourced here for better modularity within the errorverse.

Installation

Install the package from CRAN:

install.packages("roundwork")

Alternatively, install the development version from GitHub:

remotes::install_github("lhdjung/roundwork")

Get started

Round in some specific way, e.g., up from 5:

round_up(4.1679, digits = 2)
#> [1] 4.17

Use reround() to round more flexibly, especially in your own functions. You can specify a rounding procedure:

reround(4.1679, digits = 2, rounding = "up")
#> [1] 4.17

Ceil or floor numbers if certain strong assumptions are permitted:

reround(4.1679, digits = 2, rounding = "floor")
#> [1] 4.16

The default is to return two numbers — one rounded up, one rounded down. This is best for conservative assumptions, so that your conclusions won’t hinge on edge cases where these rounding procedures differ.

reround(1.275, digits = 2)
#> [1] 1.28 1.27

Bounds on the unrounded number

unround() computes the range of an unknown original number, given its rounded version. The rounding procedure determines whether the bounds are inclusive or not:

unround("3.60")
#> # A tibble: 1 × 7
#>   range                     rounding   lower incl_lower x     incl_upper upper
#>   <chr>                     <chr>      <dbl> <lgl>      <chr> <lgl>      <dbl>
#> 1 3.595 <= x(3.60) <= 3.605 up_or_down  3.60 TRUE       3.60  TRUE        3.60

unround("3.60", rounding = "up")
#> # A tibble: 1 × 7
#>   range                    rounding lower incl_lower x     incl_upper upper
#>   <chr>                    <chr>    <dbl> <lgl>      <chr> <lgl>      <dbl>
#> 1 3.595 <= x(3.60) < 3.605 up        3.60 TRUE       3.60  FALSE       3.60

unround("3.60", rounding = "even")
#> # A tibble: 1 × 7
#>   range                     rounding lower incl_lower x     incl_upper upper
#>   <chr>                     <chr>    <dbl> <lgl>      <chr> <lgl>      <dbl>
#> 1 3.595 NA x(3.60) NA 3.605 even      3.60 NA         3.60  NA          3.60

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("roundwork")

0.0.1 by Lukas Jung, 2 years ago


https://lhdjung.github.io/roundwork/, https://github.com/lhdjung/roundwork/


Report a bug at https://github.com/lhdjung/roundwork/issues


Browse source code at https://github.com/cran/roundwork


Authors: Lukas Jung [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, dplyr, magrittr, purrr, rlang, stringr, tibble

Suggests conflicted, ggplot2, knitr, rmarkdown, testthat


Imported by unsum.


See at CRAN