Hi, Is there a command that will give the total size of an R object in bytes? thanks Nicholas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Nicholas Lewin-Koh <kohnicho at comp.nus.edu.sg> writes:> Hi, > Is there a command that will give the total size of an R object in bytes?No. You can get some of the way with function (it) { x1 <- gc()[, 1] copy <- it x2 <- gc()[, 1] x1 - x2 - c(5, 6) # correct for variables and function call (fudged) }> x<-rnorm(20000) > sizeit(x)Ncells Vcells 1 20000> names(x)<-1:20000 > sizeit(x)Ncells Vcells 3 30001 And from there on things become system dependent. On x386 (Linux and also Windows IIRC) an Ncell is 20 bytes and a Vcell is 8. Oddly enough, this doesn't seem to work for functions, and I haven't got a clue why at the moment:> sizeit(glm.fit)Ncells Vcells 1 -1 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 1 Sep 2000, Nicholas Lewin-Koh wrote:> Hi, > Is there a command that will give the total size of an R object in bytes? > > thanks > NicholasYou can do it in an indirect way by duplicating (removing) the object: e.g.:> x <- gc() > x <- gc() > kfehbo1 <- kfehbo > z <- gc() > z-xfree total (Mb) Ncells -405 0 0 Vcells -136822 0 0 and then calc the mb needed for the particular object. P. ---- P.Malewski, Maschplatz 8, 38114 Braunschweig, Tel.: 0531 500965, At work: (MH-Hannover): 0511 532 3194 / Fax: 0511 532 3190, P.Malewski at tu-bs.de, peter.malewski at gmx.de, malewski.peter at mh-hannover.de. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> From: Martin Maechler <maechler at stat.math.ethz.ch> > Date: Wed, 6 Sep 2000 12:48:07 +0200 (CEST) > > >>>>> "Duncan" == Duncan Murdoch <murdoch at stats.uwo.ca> writes: > > Duncan> On Sat, 2 Sep 2000 10:38:09 +0200 (MET DST),Kjetil Kjernsmo > Duncan> <kjetil.kjernsmo at astro.uio.no> wrote in message > Duncan> <Pine.OSF.4.05.10009021034320.15448-100000 at alnair.uio.no>: > > >> Dear all, > >> > >> If I may request a feature, I would find it very useful to be able > >> to obtain a the sizes of the objects along with object names with > >> e.g. ls(). > > Duncan> In S-PLUS, objects.summary() does this. (Size means number of > Duncan> components, not size in bytes, so it's not very informative for > Duncan> some structured objects, but it definitely does let you find > Duncan> the big vectors of numbers.) Kjetil's right, it's useful. > > just the number of components... should be "easy" (well..) > writing a function that recursively sums up length() of atomic components.. > > would that really be okay?That's *not* what S-PLUS does now (if it ever did). From ?objects.summary: object.size a numeric vector giving the object sizes in bytes, as defined by function object.size. and object.size() gives the (potentially) allocated memory, including overheads. If you just want the number of components, try objects.length <- function(list) { res <- sapply(list, function(x) length(get(x))) names(res) <- list res } One possible catch is duplicated strings: zz <- rep("a long string", 10000) is not actually the size which object.size() reports (180041), and I think it is actually about 40000 bytes in R, looking at gc(). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._