title: R tcltk responsive gui during calculation
body: <p>Hello dear stack overflow community.</p>
  
  <p>i'm currently working on an R project for statistical calculations that involves a gui and also time consuming heuristics. in the gui shall be an button to start and stop the calculation and a textfield that reports the best error so far. </p>
  
  <p>so i'm stuck with the question how to keep the gui responsive during the calculation. </p>
  
  <p>some example code</p>
  
  <pre><code>require("tcltk")
  
  result&lt;-tclVar("")
  
  start&lt;-function(){
    active&lt;&lt;-TRUE
    tkconfigure(button,text="stop",command=stop)
    dostuff()
  }
  
  stop&lt;-function(){
    active&lt;&lt;-FALSE
    tkconfigure(button,text="start",command=start)
  }
  
  dostuff&lt;-function(){#this would be the optimization function
    while(active){
    tclvalue(result)&lt;-#do some stuff
    }
  }
  
  
  toplevel&lt;-tktoplevel()
  button&lt;-tkbutton(toplevel,text="start",command=start)
  entry&lt;-tkentry(toplevel,textvariable=result)
  tkpack(button)
  tkpack(entry)
  </code></pre>
  
  <p>in the do stuff function some multithreading stuff seems to be necessary. its a requirement to work on windows and linux. i'm hoping for ideas how to archive this. thanks in advance</p>