[R] callback environment for Tk buttons
Luke Tierney
luke at stat.umn.edu
Sun Feb 4 13:03:36 CET 2001
Peter Dalgaard BSA wrote:
> Luke Tierney <luke at stat.umn.edu> writes:
>
> > > If I translate this to R, I get:
> > > tt <- tktoplevel()
> > > for (i in c("hello", "HALLO"))
> > > tkpack (tkbutton (tt, text=i,
> > > command=function()cat(i,"world\n")), fill="x")
> > > tkpack (tkbutton (tt, text="dismiss",
> > > command=function()tkdestroy(tt)), fill="x")
>
> > If you don't want to create a function, use local:
> >
> > tt <- tktoplevel()
> > for (i in c("hello", "HALLO"))
> > local({
> > j <- i
> > cb <- eval(substitute(function()cat(w,"world\n"), list(w=j)))
> > tkpack (tkbutton (tt, text=j, command=cb), fill="x")
> > })
> > tkpack (tkbutton (tt, text="dismiss",
> > command=function()tkdestroy(tt)), fill="x")
> >
>
> Hmm. I thought you didn't want eval(substitute(..))?
>
> How about
>
> tt <- tktoplevel()
> for (i in c("hello", "HALLO")) {
> cb <- local({i<-i; function()cat(i,"world\n")})
> tkpack (tkbutton (tt, text=i,
> command=cb), fill="x")
> }
> tkpack (tkbutton (tt, text="dismiss",
> command=function()tkdestroy(tt)), fill="x")
>
>
THank you, peter.
That was the fryingpan and the fire of sut and paste. :-)
luke
--
Luke Tierney
University of Minnesota Phone: 612-625-7843
School of Statistics Fax: 612-624-8868
313 Ford Hall, 224 Church St. S.E. email: luke at stat.umn.edu
Minneapolis, MN 55455 USA WWW: http://www.stat.umn.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list