asSize: convert numeric value to size

asSizeR Documentation

convert numeric value to size

Description

convert numeric value to size

Usage

asSize(
  x,
  humanFriendly = TRUE,
  digits = 3,
  abbreviateUnits = TRUE,
  unitType = "bytes",
  unitAbbrev = gsub("^(.).*$", "\\1", unitType),
  kiloSize = 1024,
  sep = " ",
  ...
)

Arguments

x

numeric vector

humanFriendly

logical, currently only TRUE is accepted, whether to include human-friendly units to the output.

digits

integer number of digits used by format when formatting the number to create a character string

abbreviateUnits

logical whether to print abbreviated units, for example using k, M, G, T, P instead of kilo, mega, Giga, Tera, Peta, respectively.

unitType

character string indicating the base unit of measure, by default "bytes". Note that trailing "s" is removed when the number is singular.

unitAbbrev

character string indicating an abbreviated base unit, by default it uses the first character from unitType.

kiloSize

numeric number of base units when converting from one base unit, to one "kilo" base unit. For file sizes, this value is 1024, but for other purposes this value may be 1000.

sep

delimiter used between the numeric value and the unit.

...

other parameters passed to format.

Details

This function is intended to provide the inverse of asSize() by converting an abbreviated size into a full numeric value.

It makes one simplifying assumption, that the first character in the unit is enough to determine the unit. This assumption also means the units are currently case-sensitive.

Value

character vector representing human-friendly sizes.

See Also

Other jam string functions: breaksByVector(), cPasteSU(), cPasteS(), cPasteUnique(), cPasteU(), cPaste(), fillBlanks(), formatInt(), gsubOrdered(), gsubs(), makeNames(), mixedOrder(), mixedSortDF(), mixedSorts(), mixedSort(), mmixedOrder(), nameVectorN(), nameVector(), padInteger(), padString(), pasteByRowOrdered(), pasteByRow(), sizeAsNum(), tcount(), ucfirst(), uniques()

Examples

asSize(c(1, 10,2010,22000,52200))
#> "1 byte"   "10 bytes" "2 kb"     "21 kb"    "51 kb"

# demonstration of straight numeric units
asSize(c(1, 100, 1000, 10000), unitType="", kiloSize=100)


jmw86069/jamba documentation built on Oct. 9, 2024, 10:52 a.m.