sizeAsNum: convert size to numeric value

sizeAsNumR Documentation

convert size to numeric value

Description

convert size to numeric value

Usage

sizeAsNum(x, kiloSize = 1024, verbose = FALSE, ...)

Arguments

x

character vector. When x is numeric, it is returned as-is; otherwise x is coerced to character with as.character() and will throw an error if it fails.

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, like one thousand units is "1k units".

verbose

logical indicating whether to print verbose output. The output includes a data.frame summarizing the input, and the unit matched, and the final value. If verbose==2 it will return this data.frame for review.

...

additional arguments are ignored.

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, for example Mega requires upper-case "M", because "milli" which is not supported, requires "m".

Unit abbreviations recognized:

  • k - kilo - size is defined by kiloSize

  • M - Mega - size is defined by kiloSize ^ 2

  • G - Giga - size is defined by kiloSize ^ 3

  • T - Tera - size is defined by kiloSize ^ 4

  • P - Peta - size is defined by kiloSize ^ 5

Everything else is considered to have no abbreviated units, thus the numeric value is returned as-is.

Note that the round trip asSize() followed by sizeAsNum() will not produce identical values, because the intermediate value is rounded by digits in asSize().

Value

numeric vector representing the numeric value represented by an abbreviated size.

See Also

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

Examples

x <- asSize(c(1, 10,2010,22000,52200), unitType="")
x
#> "1"   "10" "2k"     "21k"    "51k"
sizeAsNum(x)

sizeAsNum(x, kiloSize=1000)


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