[R] callback environment for Tk buttons
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Sun Feb 4 00:45:08 CET 2001
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")
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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