From spinuvit.list at gmail.com  Wed Aug 18 10:14:56 2010
From: spinuvit.list at gmail.com (Vitaly S.)
Date: Wed, 18 Aug 2010 10:14:56 +0200
Subject: [Rd] parent.frame(1) of a S4 method is not a calling
	environment.
In-Reply-To: <AANLkTikYjCwuMv2LC_Kx2sYmgm6JYLXkEyP7xR0xKark@mail.gmail.com>
	(Hadley Wickham's message of "Tue, 17 Aug 2010 21:31:44 -0500")
References: <87d3tj4ku4.fsf@gmail.com> <4C698DAC.3090704@fhcrc.org>
	<87wrrq2ns2.fsf@gmail.com> <4C6A630C.9020802@gmail.com>
	<87sk2c3k9j.fsf@gmail.com>
	<AANLkTikYjCwuMv2LC_Kx2sYmgm6JYLXkEyP7xR0xKark@mail.gmail.com>
Message-ID: <87ocd02v7j.fsf@gmail.com>

Hadley Wickham <hadley at rice.edu> writes:

> On Tuesday, August 17, 2010, Vitaly S. <spinuvit.list at gmail.com> wrote:
>> 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.
>
> I probably should move the quoting related out of plyr into it's own
> package to facilitate this type of reuse. I think the current
> structure is quite general.

That would be neat. An S4 class "quote" which would store the parent.frame as a
slot would be great! 

>
> Hadley



[Rd] parent.frame(1) of a S4 method is not a calling environment.
Vitaly S.