From pdalgd at gmail.com  Thu Jan  6 13:31:06 2011
From: pdalgd at gmail.com (peter dalgaard)
Date: Thu, 6 Jan 2011 13:31:06 +0100
Subject: [Rd] scoping/non-standard evaluation issue
In-Reply-To: <AANLkTi=Hi=XN81xMNTGKsyw5oqU0VU+sRRBaBSPNVY_t@mail.gmail.com>
References: <009b01cbac57$532a3b80$f97eb280$@ca>
	<AANLkTi=Hi=XN81xMNTGKsyw5oqU0VU+sRRBaBSPNVY_t@mail.gmail.com>
Message-ID: <9EE05E39-820F-4524-86FE-8146F856FA55@gmail.com>


On Jan 6, 2011, at 13:11 , Kenn Konstabel wrote:

> the following seems an easy solution:
> 
> f1 <- function(mod){
>     subs <- 1:10
>     toeval <- quote(update(mod, subset=subs))
>     toeval$subset<-subs
>     eval(toeval)
>     }
> 
> f1(mod.2)

Tere, Kenn!

Yes, enforcing pass-by-value by pre-evaluating the argument will certainly defeat the nonstandard evaluation issues. Another version of the same idea is

eval(bquote(update(mod, .(subs)))

The only thing is that if the argument is ever deparsed, you might get a messy display. E.g., try eval(bquote(plot(.(rnorm(20)))))


-pd

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] scoping/non-standard evaluation issue
peter dalgaard