Dear expRts, I have a character string, say a <- "print(9**2)". How do I execute the contents of the string, parsed as R code? Do I have to open a connection and use cat(a), and parse it at the other end? Cheers Johannes -- Johannes H?sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johannes at huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")
eval(parse(text="print(9**2)")) On Thu, Jun 17, 2010 at 12:32 PM, Johannes Huesing <johannes at huesing.name> wrote:> Dear expRts, > I have a character string, say a <- "print(9**2)". How do I execute > the contents of the string, parsed as R code? Do I have to open a > connection and use cat(a), and parse it at the other end?
Peter Langfelder <peter.langfelder at gmail.com> [Thu, Jun 17, 2010 at 09:38:45PM CEST]:> eval(parse(text="print(9**2)"))cheers, I overlooked the text option.> > On Thu, Jun 17, 2010 at 12:32 PM, Johannes Huesing > <johannes at huesing.name> wrote: > > Dear expRts, > > I have a character string, say a <- "print(9**2)". How do I execute > > the contents of the string, parsed as R code? Do I have to open a > > connection and use cat(a), and parse it at the other end?-- Johannes H?sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johannes at huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")
You should also look at fortune(106) and think about possible other solutions to your overall objective. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Johannes Huesing > Sent: Friday, June 18, 2010 12:17 AM > To: Peter Langfelder > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] Read code from character string > > Peter Langfelder <peter.langfelder at gmail.com> [Thu, Jun 17, 2010 at > 09:38:45PM CEST]: > > eval(parse(text="print(9**2)")) > > cheers, I overlooked the text option. > > > > > On Thu, Jun 17, 2010 at 12:32 PM, Johannes Huesing > > <johannes at huesing.name> wrote: > > > Dear expRts, > > > I have a character string, say a <- "print(9**2)". How do I execute > > > the contents of the string, parsed as R code? Do I have to open a > > > connection and use cat(a), and parse it at the other end? > > -- > Johannes H?sing There is something fascinating about > science. > One gets such wholesale returns of > conjecture > mailto:johannes at huesing.name from such a trifling investment of fact. > http://derwisch.wikidot.com (Mark Twain, "Life on the > Mississippi") > > ______________________________________________ > 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.
Greg Snow <Greg.Snow at imail.org> [Fri, Jun 18, 2010 at 04:57:03PM CEST]:> You should also look at fortune(106) and think about possible other solutions to your overall objective.I am not installing fortune solely for this purpose but I understand that anything which smells like macro expansion is frowned upon in R circles. Yet there are situations where i want to treat code as data and data as code. As far as I gather this works only with closures in R, not with general S-expressions, so sometimes I have to resort to character strings. -- Johannes H?sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johannes at huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")