Language: R. Question: Can I specify a fixed-width font for the menu(..,graphics=T) function?
Explanation:
I recently asked this question about how a user can select a data frame row interactively:
df <- data.frame(a=c(9,10),b=c('hello','bananas')) df.text <- apply( df, 1, paste, collapse=" | " ) menu(df.text,graphics=T)

I want to | lined up. At the moment there are none; Fair enough, I didnβt fill columns of the same width. Therefore, I use format so that each column is the same width (I will write code later to automatically determine the width of the column, but ignore this time):
df.padded <- apply(df,2,format,width=8) df.padded.text <- apply( df.padded, 1, paste, collapse=" | ") menu( df.padded.text,graphics=T )

See how it is still smelly? However, if I look at df.padded , I get:
> df.padded ab [1,] " 9 " "hello " [2,] "10 " "bananas "
Thus, each cell is definitely complemented by the same length.
The reason for this is probably because the default font for this (on my system, Linux anyway) is not a fixed width.
So my question is: Is it possible to specify a fixed-width font for the menu(..,graphics=T) function?
Update
@RichieCotton noticed that if you look at menu graphics=T , it calls select.list , which in turn calls tcltk::tk_select.list .
So, it looks like I will have to change tcltk parameters for this. From @jverzani:
library(tcltk) tcl("option", "add", "*Listbox.font", "courier 10") menu(df.padded.text,graphics=T)

Given that menu(...,graphics=T) calls tcltk::tk_select.list when graphics TRUE, I assume this is a viable option, since any distribution that could display a graphical menu also primarily would have tcltk on it, since it needs to call tk_select.list .
(Aside, I cannot find anything in the documentation that would give me a hint to try tcl('option','add',...) , not to mention that this parameter was called *Listbox.font !)
Another update - we examined the select.list and menu code in more detail, and it turns out on Windows (or if .Platform$GUI=='AQUA' is Mac?), tcltk::tk_select.list is not called at all, but instead only some internal code is used. Therefore, changing '* Listbox.font' will not affect this.
I think I'm just:
- If tcltk exists, download it, set * Listbox.font to the courier and use
tcltk::tk_select.list explicitly - if it is not, try
menu(...,graphics=T) to at least get a graphical interface (which will not be monospaced, but better than nothing). - if that doesn't work either, then just go back to
menu(...,graphics=F) , which will definitely work.
Thanks to everyone.