Bug 16649

Summary: format.object_size(): Add support for IEC units KiB, MiB, GiB, ...
Product: R Reporter: Henrik Bengtsson <henrikb>
Component: WishlistAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: enhancement CC: maechler
Priority: P5    
Version: R-devel (trunk)   
Hardware: All   
OS: All   
Attachments: Patch for R/object.size.R and man/object.size.Rd

Description Henrik Bengtsson 2015-12-30 21:49:28 UTC
Created attachment 1960 [details]
Patch for R/object.size.R and man/object.size.Rd

Please consider adding support for the IEC standard for _binary_ byte size units, e.g. KiB, MiB, GiB, ...

I've attached a patch for utils/R/object.size.R and utils/man/object.size.Rd adding support for KiB, ..., YiB.  Example of output:

> format(structure(1e6, class = "object_size"), units="KiB")
[1] "976.6 KiB"
> format(structure(1e6, class = "object_size"), units="MiB")
[1] "1 MiB"
> format(structure(1e7, class = "object_size"), units="MiB")
[1] "9.5 MiB"
> format(structure(1e13, class = "object_size"), units="TiB")
[1] "9.1 TiB"
> format(structure(1e25, class = "object_size"), units="YiB")
[1] "8.3 YiB"

The patch is backward compatible, so it should not break anything.  I've scanned the R source code for usages of "Kb", "Mb", "Gb", "KB", "MB" and "GB" to find if similar support needs to be added elsewhere, but I could not find any other occurrence.

Thank you

Comment 1 Martin Maechler 2016-01-05 14:49:35 UTC
Thanks a a lot, Henrik.   I've committed (an extension) of your patch,
as svn rev 69869