[R] dimensions of a all objects

Martin Maechler maechler at stat.math.ethz.ch
Tue Jan 9 16:09:20 CET 2007


>>>>> "BaRow" == Barry Rowlingson <b.rowlingson at lancaster.ac.uk>
>>>>>     on Tue, 09 Jan 2007 14:53:05 +0000 writes:

    BaRow> Farrel Buchinsky wrote:
    >> Why will the following command not work
    >> sapply(objects(),dim)
    >> What does it say about the objects list? What does it say about the dim
    >> command?
    >> 
    >> Likewise, the following also does not work
    >> all<-ls()
    >> for (f in all) print(dim(f))

    BaRow> 'objects()' returns character strings - the names of objects - then 
    BaRow> the dim of the character strings are all NULL.

    BaRow> I'll assume that's what you are getting at - you've not posted an 
    BaRow> example or the output you are getting or why it 'does not work'.

    BaRow> Maybe you want this:
    >> sapply(objects(),function(x){dim(get(x))})
    BaRow> $f
    BaRow> NULL

    BaRow> $m
    BaRow> [1] 2 5

    BaRow> $x
    BaRow> NULL

    BaRow> $y
    BaRow> [1] 5 2

    BaRow> - where m and y are matrices, f is a function, x is a scalar.


Yes.
Since he's just interested in "print"ing, maybe

   ls.str()  # would be even more revealing (or maybe too
	     #   confusing for a newbie)

Martin



More information about the R-help mailing list