[R] Dropdown boxes in tcltk and R

jake jake at fantasticteam.com
Sun May 13 16:49:16 CEST 2007


Hello,

I'm very much a newbie in R and more so in tcltk so apologies if this 
question is stupid.  Basically I am trying to use the combobox example 
found here: 
http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/DropDown.html .

What I want to do is in that example get fruitChoice as a variable in R 
in general. When I run that code, however, and the ask for fruitChoice 
it says 'error not found'. I suspect it's because its embedded in a 
function, but I can't work out how to unravel it. I've tried something 
like this to no avail.

require(tcltk)
tclRequire("BWidget")
tt <- tktoplevel()
tkgrid(tklabel(tt,text="What's your favorite fruit?"))
fruits <- c("Apple","Orange","Banana","Pear")
comboBox <- tkwidget(tt,"ComboBox",editable=FALSE,values=fruits)
tkgrid(comboBox)

OnOK <- function()
{
    tkdestroy(tt)
    msg <- paste("Good choice! ",fruitChoice,"s are delicious!",sep="")
    tkmessageBox(title="Fruit Choice",message=msg)

}
OK.but <-tkbutton(tt,text="   OK   ",command=OnOK)
tkgrid(OK.but)
tkfocus(tt)

tkwait.window(tt)

fruitChoice <- fruits[as.numeric(tclvalue(tcl(comboBox,"getvalue")))+1]

fruitChoice

Which gives me:

Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"), 
class = "tclObj") :
        [tcl] invalid command name ".14.2".

What do I need to change to get the variable? That is, if I pick 
"orange", I want a variable with the value "orange".

Thanks for your reply, I'm sure this is something simple I've overlooked,

Jake



More information about the R-help mailing list