Call the S3 method format.object_size() to format numbers of bytes.

format_bytes(x, units = "auto", ...)

Arguments

x

A numeric vector (each element represents a number of bytes).

units, ...

Passed to format().

Value

A character vector.

Examples

xfun::format_bytes(c(1, 1024, 2000, 1e+06, 2e+08))
#> [1] "1 bytes"  "1 Kb"     "2 Kb"     "976.6 Kb" "190.7 Mb"
xfun::format_bytes(c(1, 1024, 2000, 1e+06, 2e+08), units = "KB")
#> [1] "0 Kb"        "1 Kb"        "2 Kb"        "976.6 Kb"    "195312.5 Kb"