[R] Size of objects in the workspace

Douglas Bates bates at stat.wisc.edu
Wed Feb 24 05:09:14 CET 1999


>>>>> "Mike" == Michael Meyer <michael.m.meyer at boeing.com> writes:

  Mike> Is there an easy way (or any way) to determine the size of all
  Mike> the objects in an R workspace.  I know that "dim" will work on
  Mike> matrices, "length" will work on lists, but what gives the size
  Mike> of a function?

  Mike> After I have worked for a few days I often get confused about
  Mike> what is what in the workspace, so I'm looking for something
  Mike> like "ls -l", to point me toward the big memory hogs.

This isn't exactly what you are looking for but I would recommend
trying Martin Maechler's "str" function on the objects in your
workspace.  It does not directly give the size of the object but it
does give a concise description of the type of object and an explicit
map of its structure.  This helps enormously in debugging functions
that work on complicated structures such as fitted model structures.

 R> str(str)
 function (object, ...)  
 R> data(women)
 R> str(women)
 `data.frame':  15 obs. of  2 variables:
  $ height: num  58 59 60 61 62 63 64 65 66 67 ...
  $ weight: num  115 117 120 123 126 129 132 135 139 142 ...
 R> for(i in objects(3)) if (!is.function(get(i))) {cat(i,"\n");print(str(get(i)))}
 .AutoloadEnv 
 length 1 <environment>
  - attr(*, "name")= chr "Autoloads"
 NULL
 .Device 
  chr "null device"
 NULL
 .Devices 
 Dotted pair list of 1
  $ : chr "null device"
 NULL
 .GlobalEnv 
 length 5 <environment>
 NULL
 .Last.value 
  NULL
 NULL
 .Library 
  chr "/usr/lib/R/library"
 NULL
 .Machine 
 List of 14
  $ double.eps           : num 2.22e-16
  $ double.neg.eps       : num 1.11e-16
  $ double.xmin          : num 2.23e-308
  $ double.xmax          : num 1.80e+308
  $ double.base          : int 2
  $ double.digits        : int 53
  $ double.rounding      : int 5
  $ double.guard         : int 0
  $ double.ulp.digits    : int -52
  $ double.neg.ulp.digits: int -53
  $ double.exponent      : int 11
  $ double.min.exp       : int -1022
  $ double.max.exp       : int 1024
  $ integer.max          : int 2147483647
 NULL
 .Options 
 Dotted pair list of 18
  $ prompt           : chr "R> "
  $ continue         : chr "+ "
  $ editor           : chr "vi"
  $ expressions      : int 100
  $ width            : int 65
  $ digits           : int 3
  $ contrasts        : Named chr [1:2] contr.treatment contr.poly
   ..- attr(*, "names")= chr [1:2] "unordered" "ordered"
  $ verbose          : logi FALSE
  $ check.bounds     : logi FALSE
  $ ts.eps           : num 1e-05
  $ na.action        : chr "na.omit"
  $ show.signif.stars: logi TRUE
  $ show.coef.Pvalues: logi TRUE
  $ printcmd         : chr "lpr"
  $ papersize        : chr "a4"
  $ device           : chr "X11"
  $ browser          : chr "netscape"
  $ pager            : chr "${RHOME}/bin/pager"
 NULL
 .Pars 
  chr [1:67] "adj" "ann" "ask" "bg" "bty" "cex" "cex.axis" ...
 NULL
 .Pars.readonly 
  chr [1:4] "cin" "cra" "csi" "din"
 NULL
 .Platform 
 List of 6
  $ OS.type    : chr "Unix"
  $ file.sep   : chr "/"
  $ dynlib.ext : chr ".so"
  $ show.file  :function (file)  
  $ append.file:function (f1, f2)  
  $ show.data  :function (package, lib.loc, fsep)  
 NULL
 .PostScript.Options 
 List of 11
  $ paper     : chr "default"
  $ horizontal: logi TRUE
  $ width     : num 0
  $ height    : num 0
  $ family    : chr "Helvetica"
  $ pointsize : num 12
  $ bg        : chr "white"
  $ fg        : chr "black"
  $ onefile   : logi TRUE
  $ print.it  : logi FALSE
  $ append    : logi FALSE
 NULL
 .lib.loc 
  chr [1:2] "/home/bates/library/R" "/usr/lib/R/library"
 NULL
 F 
  logi FALSE
 NULL
 LETTERS 
  chr [1:26] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" ...
 NULL
 T 
  logi TRUE
 NULL
 letters 
  chr [1:26] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" ...
 NULL
 month.abb 
  chr [1:12] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" ...
 NULL
 month.name 
  chr [1:12] "January" "February" "March" "April" "May" ...
 NULL
 pi 
  num 3.14
 NULL
 version 
 List of 12
  $ platform  : chr "i686-unknown-linux"
  $ arch      : chr "i686"
  $ os        : chr "linux"
  $ system    : chr "i686, linux"
  $ status    : chr ""
  $ status.rev: chr "0"
  $ major     : chr "0"
  $ minor     : chr "63.2"
  $ year      : chr "1999"
  $ month     : chr "January"
  $ day       : chr "12"
  $ language  : chr "R"
  - attr(*, "class")= chr "simple.list"
 NULL
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list