Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Saw this on a twitter post and think it's an awesome function by Dirk! Following on from JD Long's answer, I would do this for user friendly reading:</p> <pre><code># improved list of objects .ls.objects &lt;- function (pos = 1, pattern, order.by, decreasing=FALSE, head=FALSE, n=5) { napply &lt;- function(names, fn) sapply(names, function(x) fn(get(x, pos = pos))) names &lt;- ls(pos = pos, pattern = pattern) obj.class &lt;- napply(names, function(x) as.character(class(x))[1]) obj.mode &lt;- napply(names, mode) obj.type &lt;- ifelse(is.na(obj.class), obj.mode, obj.class) obj.prettysize &lt;- napply(names, function(x) { format(utils::object.size(x), units = "auto") }) obj.size &lt;- napply(names, object.size) obj.dim &lt;- t(napply(names, function(x) as.numeric(dim(x))[1:2])) vec &lt;- is.na(obj.dim)[, 1] &amp; (obj.type != "function") obj.dim[vec, 1] &lt;- napply(names, length)[vec] out &lt;- data.frame(obj.type, obj.size, obj.prettysize, obj.dim) names(out) &lt;- c("Type", "Size", "PrettySize", "Length/Rows", "Columns") if (!missing(order.by)) out &lt;- out[order(out[[order.by]], decreasing=decreasing), ] if (head) out &lt;- head(out, n) out } # shorthand lsos &lt;- function(..., n=10) { .ls.objects(..., order.by="Size", decreasing=TRUE, head=TRUE, n=n) } lsos() </code></pre> <p>Which results in something like the following:</p> <pre><code> Type Size PrettySize Length/Rows Columns pca.res PCA 790128 771.6 Kb 7 NA DF data.frame 271040 264.7 Kb 669 50 factor.AgeGender factanal 12888 12.6 Kb 12 NA dates data.frame 9016 8.8 Kb 669 2 sd. numeric 3808 3.7 Kb 51 NA napply function 2256 2.2 Kb NA NA lsos function 1944 1.9 Kb NA NA load loadings 1768 1.7 Kb 12 2 ind.sup integer 448 448 bytes 102 NA x character 96 96 bytes 1 NA </code></pre> <p>NOTE: The main part I added was (again, adapted from JD's answer) :</p> <pre><code>obj.prettysize &lt;- napply(names, function(x) { print(object.size(x), units = "auto") }) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload