[R] Executing a R-string

Rolf Turner r.turner at auckland.ac.nz
Wed Jan 27 20:06:25 CET 2010


On 28/01/2010, at 2:59 AM, Joe Trubisz 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.

 > set.seed(42)
 > m <- sample(0:9,42,TRUE)
 > S <- "which(m==4)"
 > eval(parse(text=S))
[1] 11 15 19 29 42

	cheers,

		Rolf Turner


######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}



More information about the R-help mailing list