Type: Package
Depends: testthat
Title: Human-Friendly Formatting Functions
Version: 1.2
Date: 2022-07-25
Author: Dustin Sallings
Maintainer: Dustin Sallings <dustin@spy.net>
Description: Format quantities of time or bytes into human-friendly strings.
License: MIT + file LICENSE
URL: https://github.com/dustin/humanFormat
BugReports: https://github.com/dustin/humanFormat/issues
NeedsCompilation: no
Packaged: 2022-08-07 06:02:06 UTC; dustin
Repository: CRAN
Date/Publication: 2022-08-07 06:30:02 UTC

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

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 <dustin@spy.net>