[R] tcl tk command function with arguments ??

ilai keren at math.montana.edu
Sat Feb 25 06:47:31 CET 2012


On Fri, Feb 24, 2012 at 5:03 PM, peter dalgaard <pdalgd at gmail.com> wrote:
>
>
> Now that's just weird... Firstly, it has nothing to do with sapply vs. for loops. It just works because you are inserting yet another function environment.

Thank you Peter, that makes more sense. As you can probably imagine,
first I made it work, then I convinced myself why. Just another of my
bad habits...

Secondly, if there was ever a point to having the buttons in the
OK.but list, it is not going to work anymore because you are assigning
each element to a different list, one per function environment.

Yes. I was aware of this but what is not going to work ? isn't the
OK.but list simply "storage" ? can it be used in some other way ? The
OP should answer if there is indeed some other application intended
that might fail, but I assumed there really wasn't a reason for this
exercise of creating the same button in a loop except for convenience.

> A more straightforward fix could be to do
>
> command = local({i <- i; function() PressedOK(i)})

Ouch! the thought to use local crossed my mind and was discarded in
favor of other (failed) attempts to "store" i before evaluation. This
is much better. Thank you again. I change my vote from my own solution
to this one.

>
> Other options might use the fact that command arguments can be R call objects, so you can insert the value of i  directly into the call using
>
> command = substitute(PressedOK(i), list(i=i))
>
> or
>
> command = bquote(PressedOK(.(i)))
>
> [ There's a bug fixed in 2.14.2-RC which prevents this from working in a for loop; for 2.14.1 and earlier, you'll need .(force(i)) ]
>
>> Cheers,
>> Elai
>>
>>
>>> Thanks
>>>
>>>
>>> --
>>> View this message in context: http://r.789695.n4.nabble.com/tcl-tk-command-function-with-arguments-tp4416470p4416470.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> R-help at 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.
>>
>> ______________________________________________
>> R-help at 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.
>
> --
> Peter Dalgaard, Professor,
> 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-help mailing list