[R-gui] How are Code Generated Names implemented in R tcltk
James Wettenhall
wettenhall at wehi.EDU.AU
Sat Aug 13 22:00:37 CEST 2005
Hi Bill,
> Hello R tcltk world:
> After a month without success, I seek help. Perhaps one of you has the
> knowledge to construct a checkbutton for each element of vector of
> variable length, select any combination of buttons, and then output the
> vector of selected buttons. The following code does not work:
Here's some code I threw together pretty quickly which I think does what
you are asking for. You may find a more elegant way.
Best wishes,
James
####################################################
Selected <- c()
library(tcltk)
Buttons <- c(2,5,7)
tt <- tktoplevel()
ButtonWidget <- list()
ButtonVar <- list()
for(i in 1:3) {
ButtonName <- paste("B", Buttons[i], sep="")
ButtonWidget[[i]] <- tkcheckbutton(tt)
ButtonVar[[i]] <- tclVar("0")
tkconfigure(ButtonWidget[[i]],text=ButtonName,
variable=ButtonVar[[i]],indicatoron=0)
tkpack(ButtonWidget[[i]])
}
OK <- tkbutton(tt,text=" OK ", command=function() {
Selected <<- c()
for(i in 1:3)
if(tclvalue(ButtonVar[[i]]) == "1")
Selected <<- c(Selected, Buttons[i])
cat(paste(Selected,collapse=","))
cat("\n")})
tkpack(OK)
####################################################
>
> require(tcltk)
> Buttons <- c(2,5,7)
> tt <- tktoplevel()
> for(i in 1:3) {
> ButtonName <- as.name(paste("B", Buttons[i], sep=""))
> ButtonName <- tkcheckbutton(tt)
> ButtonValue <- as.name(paste("B", Buttons[i], "Value", sep=""))
> ButtonValue <- tclVar("0")
> tkconfigure(ButtonName, text=paste(Buttons[i]), variable=ButtonValue,
> indicatoron=0)
> tkpack(ButtonName)
> }
> OK <- tkbutton(tt,text="OK", command=function() { for(i in 1:3) {
> if(as.character(tclvalue(paste("B",Buttons[i],"Value", sep=""))) == "1")
> Selected <<- c(Selected, Buttons[i])}} )
> tkpack(OK)
> Selecting any combination of checkbuttons results in the message "Error in
> structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"), class =
> "tclObj") : [tcl] can't read "B2Value": no such variable." When the
> evaluated results of as.name ... are entered interactively in place of the
> loop with ButtonName and ButtonValue variables, the mini GUI works. How
> would checkbutton names and checkbutton variable values generated in a
> loop be correctly implemented?
> Thanks,
> Bill Morphet, Space shuttle analyst/USU PhD statistics student
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-GUI mailing list
> R-SIG-GUI at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-gui
>
More information about the R-SIG-GUI
mailing list