Learn R Programming

humanFormat (version 1.2)

formatBytes: Format a number of bytes into a human readable string.

Description

Formats a number of bytes into a human readable string.

When invoked as formatBytes, SI sizes are used. You may specify IEC sizes by using formatIECBytes.

Usage

formatBytes(b, fmt="%.2f")
  formatSIBytes(b, fmt="%.2f")
  formatIECBytes(b, fmt="%.2f")

Arguments

b

Number of bytes

fmt

String format for the numeric part of the bytes

Examples

Run this code
  # returns "934.82 MB"
  formatBytes(934818582)

  # returns "891.51 MiB"
  formatIECBytes(934818582)

  # returns c("8.43 KB", "3.52 KB", "624.62 KB", "46", "7.36 KB")
  formatBytes(c(8429, 3525, 624624, 46, 7357))

Run the code above in your browser using DataLab