[R] Executing a R-string

RICHARD M. HEIBERGER rmh at temple.edu
Wed Jan 27 20:08:40 CET 2010


m <- c(1,4,2,3,7,5)
S <- "which(m==4)"
P <- parse(text=S)
R <- eval(P)
R

Before you do this, see fortune(106)

> fortune(106)

If the answer is parse() you should usually rethink the question.
  -- Thomas Lumley
     R-help (February 2005)

On Wed, Jan 27, 2010 at 8:59 AM, Joe Trubisz <jtrubisz at mac.com> wrote:
> Hello...
>
> In other languages (e.g. php, perl), you have the ability to create a valid
> string and execute the string to get the result. For example (in pseudo-R):
>
> S<-"which(m==4)"
> R<-exec(S)
>
> I know this does not work, but was wondering if there was an equivalent
> mechanism that I cannot find in the docs anywhere to make it work.
>
> Thanks,
> Joe
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list