Skip to content
Prev 76450 / 398502 Next

tcl/tk return problem

Duncan Murdoch wrote:
This was to provide a direct answer to the question. I think I said it 
is not a good practice. For storing temporary variables for a GUI, I 
prefer to use a dedicated workspace. The very simple functions 
assignTemp(), getTemp() and rmTemp() in the svMisc package (SciViews 
bundle) ease its use. 'TempEnv' is used in SciViews-R, and, after a 
suggestion, John Fox included it also in R Commander (called 'RcmdrEnv' 
there).

May be a modal Tk dialog box is all what is needed here... Although 
since we are speaking about "good and bad questions", I wonder if the 
whole stuff is of any value:

1??) Draw a Tk dialog just with a "Choose a directory!" and an "OK" 
button is totally useless. Why not to display tkchooseDirectory() 
directly? After all, the 'Cancel' button is there in case the user does 
not want to proceed. This error in GUI design is to place in the same 
bag as "Do you want to quit?" -> "Do you really want to quit?" -> "Are 
you really sure you really want to quit?" !!!

2??) However, if the initial idea is to place other info in the Tk 
dialog, it then makes sense. Now, if this is the case, it is not 
necessary to put tkchooseDirectory() in the OnOK() function. The 
following code is doing the job without all the problems mentioned:

 > # This is because I don't have the ReadAffy() function...
 > ReadAffy <- function(celfile.path) return(celfile.path)
 >
 > readcelfiles <- function() {
 >     require(tcltk)
 >     tt <- tktoplevel()
 >     tkgrid(tklabel(tt, text = "Choose a directory!"))
 >     tkgrid(tkbutton(tt, text = "OK",
 >          command = function() tkdestroy(tt)))
 >     tkfocus(tt)
 >     tkwait.window(tt)
 >     fileDir<-tclvalue(tkchooseDirectory())
 >     return(ReadAffy(celfile.path = fileDir))
 > }
 > readcelfiles()

So... perhaps the wrong question is not where one think it is ;-)
Best,

Philippe