Convert byte sizes into human-readable byte sizes.

# S3 method for numeric
hsize(sizes, digits=1L, units="auto", standard=getOption("hsize.standard", "IEC"),
  bytes=getOption("hsize.bytes", "B"), ...)
  # S3 method for object_size
hsize(sizes, ...)

Arguments

sizes

A numeric vector of sizes.

digits

Number of digits to be presented in the give unit.

units

A character string specifying type of units to use.

bytes

The string used for units of bytes without a prefix. Applied only if units="auto".

...

Not used.

Value

A character

vector.

Author

Henrik Bengtsson

See also

Examples

sizes <- c(1000^(0:8), 1024^(0:8))
df <- data.frame(size=sizes)
df$SI <- hsize(sizes, standard="SI")
df$TB <- hsize(sizes, units="TB")
df$IEC <- hsize(sizes, standard="IEC")
df$TiB <- hsize(sizes, units="TiB")
print(df)
#>            size     SI                 TB       IEC                 TiB
#> 1  1.000000e+00    1 B             0.0 TB       1 B             0.0 TiB
#> 2  1.000000e+03 1.0 kB             0.0 TB    1000 B             0.0 TiB
#> 3  1.000000e+06 1.0 MB             0.0 TB 976.6 KiB             0.0 TiB
#> 4  1.000000e+09 1.0 GB             0.0 TB 953.7 MiB             0.0 TiB
#> 5  1.000000e+12 1.0 TB             1.0 TB 931.3 GiB             0.9 TiB
#> 6  1.000000e+15 1.0 PB          1000.0 TB 909.5 TiB           909.5 TiB
#> 7  1.000000e+18 1.0 EB       1000000.0 TB 888.2 PiB        909494.7 TiB
#> 8  1.000000e+21 1.0 ZB    1000000000.0 TB 867.4 EiB     909494701.8 TiB
#> 9  1.000000e+24 1.0 YB 1000000000000.0 TB 847.0 ZiB  909494701772.9 TiB
#> 10 1.000000e+00    1 B             0.0 TB       1 B             0.0 TiB
#> 11 1.024000e+03 1.0 kB             0.0 TB   1.0 KiB             0.0 TiB
#> 12 1.048576e+06 1.0 MB             0.0 TB   1.0 MiB             0.0 TiB
#> 13 1.073742e+09 1.1 GB             0.0 TB   1.0 GiB             0.0 TiB
#> 14 1.099512e+12 1.1 TB             1.1 TB   1.0 TiB             1.0 TiB
#> 15 1.125900e+15 1.1 PB          1125.9 TB   1.0 PiB          1024.0 TiB
#> 16 1.152922e+18 1.2 EB       1152921.5 TB   1.0 EiB       1048576.0 TiB
#> 17 1.180592e+21 1.2 ZB    1180591620.7 TB   1.0 ZiB    1073741824.0 TiB
#> 18 1.208926e+24 1.2 YB 1208925819614.6 TB   1.0 YiB 1099511627776.0 TiB