[R] Putting an index explicitly into function code --- a curiosity.
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Jan 8 16:11:41 CET 2012
On Sun, Jan 8, 2012 at 7:50 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> On 12-01-07 2:44 PM, cberry at tajo.ucsd.edu wrote:
>>
>> Duncan Murdoch<murdoch.duncan at gmail.com> writes:
>>
>>> On 12-01-06 10:21 PM, Rolf Turner wrote:
>>>>
>>>> On 07/01/12 15:51, R. Michael Weylandt<michael.weylandt at gmail.com>
>>>> wrote:
>>>>>
>>>>> I imagine the answer will involve lazy evaluation and require you use
>>>>> force() but I'm not quite qualified to pronounce and not at a computer to
>>>>> test.
>>>>
>>>>
>>>> I think you've got it; I tried
>>>>
>>>> junk<- vector("list",4)
>>>> for(i in 1:4) {
>>>> junk[[i]]<- eval(bquote(function(x){42 + .(force(i))*x}))
>>>> }
>>>>
>>>> and got the result that I wanted. Still don't completely understand,
>>>> but
>>>> it at least makes vague sense and makes me a bit more comfy.
>>>
>>>
>>> I'm not so sure. The index in a for loop isn't supposed to be a
>>> promise. To me, it looks like a bug, maybe in bquote()...
>>>
>>
>> Duncan,
>>
>> IIUC, the promise is created by bquote().
>
>
> No, as Gabor said, there was no promise there. Luke Tierney tracked it down
> to a bug, which is now fixed in R-patched and R-devel (as of revision
> r58074).
>
I think it has been discussed before but this is a good example where
it would have been nice to have a function in R similar to the
ispromise function in my post. promises tend to be mysterious since
there is no way short of what I did to actually find out if an object
is a promise or not. (Also it would be useful to have a facility for
copying objects without forcing promises -- something else that can
only be done at the C level currently.)
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list