Formats bytes into human-readable units, from "kB" (10^3) to "YB" (10^23).

size_humanreadable(bytes, decimals = 1, decimal.mark = dec_mark())

Arguments

bytes

number of bytes

decimals

precision, not used for bytes and kilobytes

decimal.mark

decimal mark to use, defaults to dec_mark()

Details

If using object.size() on an object, this function is equal to using format2() to format the object size.

Examples

size_humanreadable(c(12, 1234, 123456, 12345678))
#> [1] "12 B"    "1.2 kB"  "121 kB"  "11.8 MB"

size_humanreadable(1024 ^ c(0:4))
#> [1] "1 B"    "1.0 kB" "1.0 MB" "1.0 GB" "1.0 TB"