From zhengxin at mail.nih.gov  Thu Apr  7 23:47:36 2011
From: zhengxin at mail.nih.gov (Zheng, Xin (NIH) [C])
Date: Thu, 7 Apr 2011 17:47:36 -0400
Subject: [Rd] anyway to get R unevaluated expr independent on arguments
In-Reply-To: <94F14593-CC2D-4EB5-A81B-E69B32E05AE0@r-project.org>
References: <E068E36B85D57D449ECEC6894C0F3DCB02A143AB56@NIHMLBX01.nih.gov>
	<94F14593-CC2D-4EB5-A81B-E69B32E05AE0@r-project.org>
Message-ID: <E068E36B85D57D449ECEC6894C0F3DCB02A143AB5C@NIHMLBX01.nih.gov>

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



[Rd] anyway to get R unevaluated expr independent on arguments
Zheng, Xin (NIH