Round and format numeric vectors; standardising trailing zeros

pretty_round(num, digits = 2, to_pass = c("", " ", "Inf", NaN, NA), ...)

Arguments

num

A numeric or character vector coercible to a numeric vector. Empty character vectors will be returned by the function.

digits

Integer indicating the number of decimal places to be used.

to_pass

A character vector specifying what to pass without reformating, by default this includes; NA, NaN, "Inf", "", and " ".

...

Pass additional arguements to format.

Value

A rounded numeric vector formatted as a character vector with trialing zeros.

See also

format, and round for additional information

Examples

## Rounding a single number pretty_round(2.1, digits = 1)
#> [1] "2.1"
## Rounding with trailing whitespace pretty_round(2.1, digits = 2)
#> [1] "2.10"
##Rounding a vector pretty_round(c(2.13, 2.1, 4.165, 8.2323242, 1), digits = 2)
#> [1] "2.13" "2.10" "4.17" "8.23" "1.00"
## Passed without rounding pretty_round(c("", " ", "Inf", NaN, NA), digits = 2)
#> [1] "" "" "Inf" "NaN" NA