Given a<-"c(1,2,3,4,5)" How canĀ I evaluate the variable a to return a (numeric) vector comprising of 1,2,3,4,5? Thanks. [[alternative HTML version deleted]]
eval(parse(text = a)) But this is rarely a good idea....perhaps you could say a little more about your overall goal and we could direct you to a more "R"-ish solution? library(fortunes) fortune("rethink") Michael On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolum <aa2e72e at yahoo.co.uk> wrote:> Given > > a<-"c(1,2,3,4,5)" > > How can? I evaluate the variable a to return a (numeric) vector comprising of 1,2,3,4,5? Thanks. > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
> mytext <- "c(1,2,3,4,5)" > a <- eval(parse(text=mytext)) > a[1] 1 2 3 4 5 will do this, if there's no better way to accomplish your actual goal. Sarah On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolum <aa2e72e at yahoo.co.uk> wrote:> Given > > a<-"c(1,2,3,4,5)" > > How can? I evaluate the variable a to return a (numeric) vector comprising of 1,2,3,4,5? Thanks. > > ? ? ? ?[[alternative HTML version deleted]] > >-- Sarah Goslee http://www.functionaldiversity.org
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20120118/ef4ab0e3/attachment.pl>
On Wed, Jan 18, 2012 at 1:18 PM, Ajay Askoolum <aa2e72e at yahoo.co.uk> wrote:> > Given > > a<-"c(1,2,3,4,5)" > > How can? I evaluate the variable a to return a (numeric) vector comprising of 1,2,3,4,5? Thanks.You can also use an "active binding": ? ? > makeActiveBinding('a', function(){c(1,2,3,4,5)}, .GlobalEnv) ? ? > a ? ? [1] 1 2 3 4 5 However, I agree with the other posters---resorting to these kinds of tricks is usually a bad sign. -Charlie
for my info, why is this rarely a good idea? Is that the case for this particular example , or is eval(paste()) generally rarely a good idea? --Peter Op 18-1-2012 22:22, R. Michael Weylandt schreef:> eval(parse(text = a)) > > But this is rarely a good idea....perhaps you could say a little more > about your overall goal and we could direct you to a more "R"-ish > solution? > > library(fortunes) > fortune("rethink") > > Michael > > On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolum<aa2e72e at yahoo.co.uk> wrote: >> Given >> >> a<-"c(1,2,3,4,5)" >> >> How can I evaluate the variable a to return a (numeric) vector comprising of 1,2,3,4,5? Thanks. >> >> [[alternative HTML version deleted]] >> >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.