[R] Discrepancy in help for object.size() and question on how to round object sizes
Jennifer Lyon
jennifer.s.lyon at gmail.com
Sun Jul 25 13:58:35 CEST 2010
I think there is a discrepancy In the help for object.size().
In the usage section there is the comment:
## S3 method for class 'object_size':
while in the value section there is the text:
An object of class ‘"object.size"’ ...
And R itself says:
> class(object.size(letters))
[1] "object_size"
Also, I was trying to print out object sizes in Kb, but rounded to
whole number of units, but I could not
figure out how to do that without having to replicate the math in the
print method for object.size.
> tmp<-numeric(100000)
> object.size(tmp)
800024 bytes
> print(object.size(tmp), units="Kb")
781.3 Kb
What I want is 781 Kb, but it wasn't obvious how to get there. The
following seemed wrong, and
didn't work:
> print(signif(object.size(tmp),1), units="Kb")
781.2 Kb
> print(round(object.size(tmp)), units="Kb")
781.3 Kb
I know I can just get the result in bytes and divide by 1024, and then
round, but it seemed like there
should be a more straightforward way, so any suggestions are welcome.
Thanks!
Jen
> sessionInfo()
R version 2.11.1 (2010-05-31)
i686-pc-linux-gnu
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics utils datasets grDevices methods base
other attached packages:
[1] RColorBrewer_1.0-2
loaded via a namespace (and not attached):
[1] tools_2.11.1
More information about the R-help
mailing list