How does one turn a character string back into an object? I would like to take character strings and use them as objects, a process that I think is the reverse of deparse( substitute(X)). E.g., I would like to get the variable names from the fourth object listed with objects(), something like names(objects()[4]), but of course that doesn't work. Thanks Henry Dr. M. Henry H. Stevens Postdoctoral Associate Department of Ecology, Evolution, & Natural Resources 14 College Farm Road Cook College, Rutgers University New Brunswick, NJ 08901-8551 email: hstevens at rci.rutgers.edu phone: 732-932-9631 fax: 732-932-8746 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 Tue, 1 May 2001, Martin Henry H. Stevens wrote:> How does one turn a character string back into an object? > > I would like to take character strings and use them as objects, a process > that I think is the reverse of deparse( substitute(X)).get() -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 1 May 2001, Martin Henry H. Stevens wrote:> How does one turn a character string back into an object? > > I would like to take character strings and use them as objects, a process > that I think is the reverse of deparse( substitute(X)). > E.g., I would like to get the variable names from the fourth object listed > with objects(), > something like > > names(objects()[4]), but of course that doesn't work. >Amazingly, the opposite of deparse() is parse(), as suggested by help(deparse)> parse(text="trees")[[1]]trees So you can get the object with eval() and do eg> data(trees) > names(eval(parse(text="trees")[[1]]))[1] "Girth" "Height" "Volume" or plug the parsed name into an expression like> expr<-substitute(names(obj),list(obj=parse(text="trees")[[1]])) > exprnames(trees)> eval(expr)[1] "Girth" "Height" "Volume" -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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._