[R] evaluating the contents of a string
David A Richmond
richmond at saintmarys.edu
Fri Oct 5 00:23:57 CEST 2001
On Mon, 1 Oct 2001, Thomas Lumley wrote:
> In general, this sort of question is frequently a sign that someone is
> doing things the hard way. There are some real situations where you need
> to operate on strings like this, but they are fairly rare.
Well, actually I don't know if I'm reinventing the wheel here, but my
objective was to write a function which lists the objects in memory with
characteristic info, like data type, dimensions, and memory used. so I use
ls(pos=1) to get the list of objects at the 'root' level, and then use
get(i,pos=1) to get information about each object, then display it in a
table. It works nicely with get, and I can make it available if anyone's
interested. (I call it "describe" and it displays the name, type,
dimensions and size of each object)
dave richmond
On Mon, 1 Oct 2001, Thomas Lumley wrote:
> On Fri, 28 Sep 2001, David A Richmond wrote:
> <snip>
> > is there a function to pass bname to such that dim returns the dimensions
> > of b?
> <snip>
>
> As already pointed out, eval(parse(text=bname)) will return the object
> whose name is in the text string. Another way is get(bname), which is more
> specific (it gets objects by name, rather than evaluating arbitrary code).
>
> In general, this sort of question is frequently a sign that someone is
> doing things the hard way. There are some real situations where you need
> to operate on strings like this, but they are fairly rare.
>
> For example, if you have a collection of arrays and may want the
> dimensions of any one of them, you could put them in a list
>
>
> listofarrays<-list()
> listofarrays$b <- matrix(1:9,3,3)
> dim(listofarrays$b)
>
> and even
> bname<-"b"
> dim(listofarrays[[bname]])
>
>
> -thomas
>
> Thomas Lumley Asst. Professor, Biostatistics
> tlumley at u.washington.edu University of Washington, Seattle
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|David Richmond It works on a |
+ Dept. of Sociology complex scientific +
|Saint Mary's College principle, known as |
+ Notre Dame, IN 46556 "pot luck." +
|219-284-4517 - The Doctor |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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