[Rd] scoping/non-standard evaluation issue

peter dalgaard pdalgd at gmail.com
Thu Jan 6 13:31:06 CET 2011

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)))))


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

More information about the R-devel mailing list