Re: [Rd] anyway to get R unevaluated expr independent on arguments

From: Zheng, Xin (NIH) [C] <zhengxin_at_mail.nih.gov>
Date: Thu, 07 Apr 2011 17:47:36 -0400

Thank you very much. I learned a lot.

Regards,
Xin

-----Original Message-----
From: Simon Urbanek [mailto:simon.urbanek_at_r-project.org] Sent: Thursday, April 07, 2011 5:42 PM
To: Zheng, Xin (NIH) [C]
Cc: r-devel_at_r-project.org
Subject: Re: [Rd] anyway to get R unevaluated expr independent on arguments

On Apr 7, 2011, at 5:18 PM, Zheng, Xin (NIH) [C] wrote:

> Hi there,
>
> Suppose the cmd is "a<-3", I can parse the cmd sexp with R_ParseVector and eval it. My question is - is it possible to parse a cmd like "a <- ?", afterwards evaluation will give corresponding result depend on different argument? In other words, '?' is just a placeholder.
>

Well, you can use a dummy symbol and replace it later, e.g. parse "a <- `*dummy*`" and then before you evaluate you simply replace all occurrences of the "*dummy*" symbol with any value you want.

That said, we are in a functional language, so you can actually do it more natively by using a closure like "function(.var1){ a <- .var1 }" - that saves you the substitution part and is more clean.

Cheers,
Simon



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 07 Apr 2011 - 21:50:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 21:50:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive