How do I set values to a Tk combobox in R

I sometimes have a dropdown box with only one item to choose from, but this item might be a string with spaces. How can I do this in R? Here is the problem:

library(tcltk2)
root<-tktoplevel()
v <- tclVar()
d <- tk2combobox(root, textvariable=v)
tkpack(d)

# works
tkconfigure(d, values=c("a string with spaces", "a second string"))

# inserts four items instead of one
tkconfigure(d, values=c("a string with spaces"))

Any hint appreciated!

Answers


Try this:

spaceystr <- tclVar("a string with spaces")
tkconfigure(d, textvariable = spaceystr)

An alternative is also available that actually puts the string in the drop-down which the above does not:

tkconfigure(d, values=as.tclObj("a string with spaces", drop=FALSE))

This is hinted at, although not actually illustrated, in the help page for TclInterface.


Need Your Help

How to correct for perspective when plotting a 3D triangle with texture?

c# 3d gdi

I have been working on a 3D rendering project as a technical excersise to see if I can replicate what a lot of the 3D frameworks do already: all the way from loading the model to plotting the trian...

Cost of each class in Java application - Fewer huge classes or Several smaller ones

java performance java-ee memory

For every new Class added to a Java application, what is the cost in terms of memory?