Skip to contents

Use pretty_num() to format numbers compute_num() is the underlying engine that may be useful for custom formatting.

Usage

pretty_num(number, style = c("default", "nopad", "6"))

compute_num(number, smallest_prefix = "y")

Arguments

number

Numeric vector, number related to a linear quantity.

style

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.

smallest_prefix

A character scalar, the smallest prefix to use.

Value

Character vector, the formatted sizes. For compute_num, a data frame with columns amount, prefix, negative.

Examples

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"