convert size to numeric value
Arguments
- x
charactervector. Whenxis numeric, it is returned as-is; otherwise x is coerced tocharacterwithas.character()and will throw an error if it fails.- kiloSize
numericnumber 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
logicalindicating whether to print verbose output. The output includes adata.framesummarizing the input, and the unit matched, and the final value. Ifverbose==2it will return thisdata.framefor 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 bykiloSizeM- Mega - size is defined bykiloSize ^ 2G- Giga - size is defined bykiloSize ^ 3T- Tera - size is defined bykiloSize ^ 4P- Peta - size is defined bykiloSize ^ 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().
See also
Other jam string functions:
asSize(),
breaksByVector(),
fillBlanks(),
formatInt(),
gsubOrdered(),
gsubs(),
makeNames(),
nameVector(),
nameVectorN(),
padInteger(),
padString(),
pasteByRow(),
pasteByRowOrdered(),
tcount(),
ucfirst()