Skip to contents

Use pretty_bytes() to format bytes. compute_bytes() is the underlying engine that may be useful for custom formatting.

Usage

pretty_bytes(bytes, style = c("default", "nopad", "6"))

compute_bytes(bytes, smallest_unit = "B")

Arguments

bytes

Numeric vector, number of bytes.

style

Formatting style:

  • "default" is the original pretty_bytes 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_unit

A character scalar, the smallest unit to use.

Value

Character vector, the formatted sizes. For compute_bytes, a data frame with columns amount, unit, negative.

Examples

bytes <- c(1337, 133337, 13333337, 1333333337, 133333333337)
pretty_bytes(bytes)
#> [1] "  1.34 kB" "133.34 kB" " 13.33 MB" "  1.33 GB" "133.33 GB"
pretty_bytes(bytes, style = "nopad")
#> [1] "1.34 kB"   "133.34 kB" "13.33 MB"  "1.33 GB"   "133.33 GB"
pretty_bytes(bytes, style = "6")
#> [1] "1.3 kB" "133 kB" " 13 MB" "1.3 GB" "133 GB"