[Rd] parent.frame(1) of a S4 method is not a calling environment.
Vitaly S.
spinuvit.list at gmail.com
Wed Aug 18 01:13:44 CEST 2010
Duncan Murdoch <murdoch.duncan at gmail.com> writes:
> Vitaly S. wrote:
>> Martin Morgan <mtmorgan at fhcrc.org> writes:
>>
>>>> So, can I be sure that for such functions parent.frame(2) will always work?
>>>> What are the additional rules?
>>>>
>>> callNextMethod() will cause additional problems; the idea that you'll
>>> grab things from somewhere other than function arguments doesn't seem
>>> like a robust design, even if it's used in some important parts of R.
>>>
>>> Martin
>>>
>>>
>>
>> That make it difficult to handle unevaluated expressions in methods. A solution
>> would be to explicitly require the users to use quote() or expression(), and
>> then to use the "expression" in the signature. Slightly unpleasant, though.
>>
>>
>
> You could use formulas for that. If you pass in
>
> formula = ~ x + y*z
>
> then environment(formula) will be the right evaluation environment, and formula[[2]] will be the unevaluated x +
> y*z.
>
> Duncan Murdoch
Thank you Duncan, I didn't know that.
For programmatic use though, formula interface is slightly inconvenient. A
specialized function and class would be desirable. With the advent of more and
more complex S4 classes, unevaluated expressions in methods calls will became a
necessity, that's my feeling.
Thank you.
Vitaly.
>
>> Standardised, simpler syntax like .() in ggplot and plyr, would be handy here.
>> Hopefully .() is not grabbed for something else in meanwhile:).
>>
>> Vitaly.
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
More information about the R-devel
mailing list