Use pretty_num() to format numbers compute_num() is the underlying
engine that may be useful for custom formatting.
pretty_num(number, style = c("default", "nopad", "6"))
compute_num(number, smallest_prefix = "y")Numeric vector, number related to a linear quantity.
Formatting style:
"default" is the original pretty_num formatting, and it always
pads the output, so that all vector elements are of the same width,
"nopad" is similar, but does not pad the output,
"6" always uses 6 characters,
The "6" style is useful if it is important that the output always
has the same width (number of characters), e.g. in progress bars.
See some examples below.
A character scalar, the smallest prefix to use.
Character vector, the formatted sizes.
For compute_num, a data frame with columns amount, prefix,
negative.
numbers <- c(1337, 1.3333e-5, 13333337, 1333333337, 133333333337)
pretty_num(numbers)
#> [1] " 1.34 k" " 13.33 u" " 13.33 M" " 1.33 G" "133.33 G"
pretty_num(numbers, style = "nopad")
#> [1] "1.34 k" "13.33 u" "13.33 M" "1.33 G" "133.33 G"
pretty_num(numbers, style = "6")
#> [1] "1.34 k" "13.3 u" "13.3 M" "1.33 G" " 133 G"