convert numeric value or R object to human-readable size
Usage
asSize(
x,
digits = 3,
abbreviateUnits = TRUE,
unitType = "bytes",
unitAbbrev = gsub("^(.).*$", "\\1", unitType),
kiloSize = 1024,
sep = " ",
...
)
Arguments
- x
numeric
vector, classobject_size
which is converted tonumeric
, any other R object is converted to a singlenumeric
value usingutils::object.size()
.- digits
integer
number of digits used bybase::format()
when formatting the number to create a character string- abbreviateUnits
logical
, default TRUE, 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 fromunitType.
- kiloSize
numeric
, default 1024, number of base units when converting from to one "kilo" base unit. For computer-based size such as file size and object size, this value is 1024. For other purposes, such as scientific or monetary numbers, this value should usually be 1000.- sep
delimiter
used between the numeric value and the unit, default " ".- ...
other parameters passed to
base::format()
.
Value
character
vector representing human-friendly size,
based upon the kiloSize
argument to determine whether to
report byte (1024) or scientific (1000) units.
Details
This function returns human-readable size based upon numeric
input.
Alternatively, when input is any other R object, it calls
utils::object.size()
to produce a single numeric
value which is then
used to produce human-readable size.
The default behavior is to report computer size in bytes, where
1024 is considered "kilo", however argument kiloSize
can be
used to produce values where kiloSize=1000
which is suitable
for monetary and other scientific values.
See also
Other jam string functions:
breaksByVector()
,
fillBlanks()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
nameVector()
,
nameVectorN()
,
padInteger()
,
padString()
,
pasteByRow()
,
pasteByRowOrdered()
,
sizeAsNum()
,
tcount()
,
ucfirst()