Package 'humanFormat'

Title: Human-Friendly Formatting Functions
Description: Format quantities of time or bytes into human-friendly strings.
Authors: Dustin Sallings
Maintainer: Dustin Sallings <[email protected]>
License: MIT + file LICENSE
Version: 1.2
Built: 2024-11-24 03:08:45 UTC
Source: https://github.com/dustin/humanformat

Help Index


Duration constants

Description

These constants are used to express the number of nanoseconds in different time units.

Usage

kNanosecond
kMicrosecond
kMillisecond
kSecond
kMinute
kHour

Details

These are useful for computing specific time durations or for converting from quantities in one unit to another unit (e.g. time in milliseconds to time in nanoseconds for duration formatting).

  • kNanosecond: One nanosecond;

  • kMicrosecond: One microsecond (1000 nanosecond);

  • kMillisecond: One millisecond (1000 microseconds);

  • kSecond: One second (1000 milliseconds);

  • kMinute: One minute (60 seconds);

  • kHour: One hour (60 minutes).

Examples

# To calculate 4 minute, 3 seconds and 14 microseconds:
  4*kMinute + 3*kSecond + 14*kMicrosecond

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

# 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))

Format nanosecond durations into human readable strings.

Description

Format individual or vectors of durations into human friendly text.

Usage

formatDuration(ns)
  formatNanoseconds(ns)

  formatMicroseconds(us)
  formatMilliseconds(ms)
  formatSeconds(s)

Arguments

ns

Duration in nanoseconds

us

Duration in microseconds

ms

Duration in milliseconds

s

Duration in seconds

See Also

durationConstants constants for various duration lengths

Examples

formatDuration(0)
  formatDuration(1)
  formatNanoseconds(34)

  formatMicroseconds(235)

  formatMilliseconds(2487)

  formatSeconds(7213)

  formatDuration(c(0, 1, 1000, 2039, 205958, 284859249525))

Format numbers into human readable strings

Description

When working with durations, bytes, and other items with odd bases, it's often useful to format the numbers into human readable units.

Details

Package: humanFormat
Type: Package
Version: 1.1
Date: 2016-05-13
License: MIT
BugReports: https://github.com/dustin/humanFormat/issues

Author(s)

Dustin Sallings

Maintainer: Dustin Sallings <[email protected]>