On 10 Apr 2014, at 16:59 , Paul Johnson <pauljoh...@gmail.com> wrote:

> I've been reading quite a while on this question, testing lots of
> ideas. The quote function seems to work, but I worry about how the R
> runtime environment finds all the pieces if I pass them through this
> way.
> 
> mySpecialFeature <- function(model, ci){
>    pargs <- list(quote(model), quote(model.frame(model)[1:3, ]))
>    res <- do.call(myRegFit, pargs)
>    print(res)
> }
> 
> See, that fixes it:
> 
>> mySpecialFeature (m1)
> debugging in: (function (model, nd)
> predict(model, nd))(model, model.frame(model)[1:3, ])
> debug: predict(model, nd)
> Browse[2]> c
> exiting from: (function (model, nd)
> predict(model, nd))(model, model.frame(model)[1:3, ])
>          1           2           3
> -0.04755431  0.35162844 -0.11715522
>> 
> 
> Are there dangers in this I don't know about?
> 

I don't think so. A similar issue made the rounds quite recently over on 
R-devel ("Problem with do.call()") and the quote() trick was mentioned as a 
fix. 

The only potential issue that I can see is the fairly obvious one that the 
quoted arguments are evaluated later than unquoted ones, and possibly not at 
all due to lazy evaluation. This is of course largely the point of the 
maneuver, but there is also a slight risk that the object could change or 
disappear due to side effects when evaluating other arguments. This isn't 
different from the usual perils of lazy evaluation, though.

-pd


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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to