[Rd] Wishlist - better object.size() function
Benjamin Hofner
Benjamin.Hofner at imbe.med.uni-erlangen.de
Tue Nov 18 14:30:36 CET 2008
Some time ago I came across the function object.size() to estimate the
size of an R object. I don't know if the behavior of the function is
intended to be quite "user unfriendly" as it is right now or if just
nobody was thinking/caring about it.
I have two suggestions to improve it:
- Why is it named object.size() and not just size()? The latter would be
far more intuitive and shorter and as far as I know there is no other
function size (in the base distribution).
- Why is the function returning the size in bytes? This is (in most
cases) overly accurate and for humans hard to read. I would suggest to
have it printed in mb per default and additionally add a switch to
choose the appropriate unit.
This is a first proposal:
size <- function(x, type=c("mb","byte","kb","gb"), digits=3){
type <- match.arg(type)
RET <- switch(type,
byte = object.size(x),
kb = object.size(x)/1024,
mb = object.size(x)/(1024^2),
gb = object.size(x)/(1024^3))
cat(round(RET,digits), type, "\n")
invisible(RET)
}
I think this would improve the usability of the function a lot.
Thanks,
Benjamin
--
******************************************************************************
Dipl.-Stat. Benjamin Hofner
Institut für Medizininformatik, Biometrie und Epidemiologie
Friedrich-Alexander-Universität Erlangen-Nürnberg
Waldstr. 6 - 91054 Erlangen - Germany
Tel: +49-9131-85-22707
Fax: +49-9131-85-25740
http://www.imbe.med.uni-erlangen.de/~hofnerb/
http://www.benjaminhofner.de
******************************************************************************
More information about the R-devel
mailing list