Skip to content
Back to formatted view

Raw Message

Message-ID: <9EE05E39-820F-4524-86FE-8146F856FA55@gmail.com>
Date: 2011-01-06T12:31:06Z
From: Peter Dalgaard
Subject: scoping/non-standard evaluation issue
In-Reply-To: <AANLkTi=Hi=XN81xMNTGKsyw5oqU0VU+sRRBaBSPNVY_t@mail.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