MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #16321] Vectorize utils::object.size and friends #5737

Open MichaelChirico opened 4 years ago

MichaelChirico commented 4 years ago

utils::object_size accepts only a single item as an argument, and the 'object_size' methods only support a scalar argument, making it inconvenient to get and manipulate object sizes for multiple objects.

For instance, getting the sizes of all objects in the current namespace requires:

sizes <- sapply( ls(), utils:object.sizes) sizes

which loses the formatting provided by utils:::print.object_size via utils:::format.object_size.

To get around this, we've provided gdata::object_size and friends, which are essentially vectorized wrappers or work-alikes for utils::object size, etc.

E.g.:

a <- rnorm(1e3); b <- rnorm(1e4)
gdata::object.size( a, b )

[1] 8 kB 80 kB

Extending utils::object.size to support multiple arguments and vectorizing utils:::format.object_size and utils::print.object_size would obviate the need for these functions in gdata.


METADATA

MichaelChirico commented 4 years ago

In addition, it may be a good idea to switch to the IEC standard units:

   Name        System  Symbol  Size        Conversion      
   byte        binary    B     2^3         8 bits          
   kilobyte   decimal    kB    10^3        1000 bytes      
   kibibyte    binary   KiB    2^{10}      1024 bytes      
   megabyte   decimal    MB    (10^3)^2    1000 kilobytes  
   mebibyte    binary   MiB    (2^{10})^2  1024 kibibytes  
   gigabyte   decimal    GB    (10^3)^3    1000 megabytes  
   gibibyte    binary   GiB    (2^{10})^3  1024 mebibytes  
   terabyte   decimal    TB    (10^3)^4    1000 gigabytes  
   tebibyte    binary   TiB    (2^{10})^4  1024 gibibytes  
   petabyte   decimal    PB    (10^3)^5    1000 terabytes  
   pebibyte    binary   PiB    (2^{10})^5  1024 tebibytes  
   exabyte    decimal    EB    (10^3)^6    1000 petabytes  
   exbibyte    binary   EiB    (2^{10})^6  1024 pebibytes  
   zettabyte  decimal    ZB    (10^3)^7    1000 exabytes   
   zebibyte    binary   ZiB    (2^{10})^7  1024 exbibytes  
   yottabyte  decimal    YB    (10^3)^8    1000 zettabytes 
   yebibyte    binary   YiB    (2^{10})^8  1024 zebibytes  

where Zi and Yi are GNU extensions to IEC.

References: Wikipedia: <URL: http://en.wikipedia.org/wiki/Byte> <URL: http://en.wikipedia.org/wiki/SI_prefix> <URL: http://en.wikipedia.org/wiki/Binary_prefix>

 GNU manual for coreutils: <URL:
 http://www.gnu.org/software/coreutils/manual/html_node/Block-size.html#Block-size>

METADATA