[R] charge a vector with variables and to use as variable in a checkbutton?

solares@unsl.edu.ar solares at unsl.edu.ar
Tue Sep 9 17:10:06 CEST 2003


hello, how i cant to charge in form dynamic a checkbutton, try to do it 
with a vector be charged automaticamente but not
works, for example

library(tcltk)
tt<-tktoplevel()
f<-tkframe(tt)
tkpack(f)
i<-2
if (i==1) {b1<-tkcheckbutton
(f,text="b1",variable="b1",relief="raised");tkpack(b1);print(tclvalue
("b1"))}else if (i==2) {b1<-tkcheckbutton
(f,text="b1",variable="b1",relief="raised");tkpack(b1);print(tclvalue
("b1"));b2<-tkcheckbutton(f,text="b2",variable="b2",relief="raised");tkpack
(b2);print(tclvalue("b2"))}else if (i==3) {b1<-tkcheckbutton
(f,text="b1",variable="b1",relief="raised");tkpack(b1);print(tclvalue
("b1"));b2<-tkcheckbutton(f,text="b2",variable="b2",relief="raised");tkpack
(b2);print(tclvalue("b2"));b3<-tkcheckbutton
(f,text="b3",variable="b3",relief="raised");tkpack(b3);print(tclvalue
("b3"))}

i<-3
switch(i,{b1<-tkcheckbutton
(f,text="b1",variable="b1",relief="raised");tkpack(b1)},
{b1<-tkcheckbutton(f,text="b1",variable="b1",relief="raised");tkpack
(b1);b2<-tkcheckbutton(f,text="b2",variable="b2",relief="raised");tkpack
(b2)},
{b1<-tkcheckbutton(f,text="b1",variable="b1",relief="raised");tkpack
(b1);b2<-tkcheckbutton(f,text="b2",variable="b2",relief="raised");tkpack
(b2);;b3<-tkcheckbutton(f,text="b3",variable="b3",relief="raised");tkpack
(b3)})

as seeing I should charge in form estatic each checkbutton at to say the 
value "i" because I cannot do somewhere as:
b1<-0;b2<-0;b3<-0
b<-c(b1,b2,b3) #vector b contain three variables
j<-3;i<-1
while (i<=j){ 
 b[i]<-tkcheckbutton(f,text="b[i]",variable="b[i]",relief="raised")
#how b[i] is the same "variable" all the time for checkbutton
 tkpack(b[i])
 i<-i+1
}

Thanks Ruben




More information about the R-help mailing list