wait (int n): int

Suspends execution for the time given by n in milliseconds. The user interface remains responsive during the wait time. The function returns 0 when the [Stop] button was hit or quit was called, otherwise nonzero. If n is negative, the function checks and updates the user interface only every nth time, for not delaying fast loops. Use wait in a loop for avoiding unresponsiveness during long computations or external function calls. For displaying progress during very long processes, use progress instead.


n - wait time in milliseconds when positive, user interface update frequency when negative, 0 for immediate user interface update.


0 when the script is to be terminated, 1 otherwise.



Rx("TrainNeuralNet()",1); // start a long computation
while(Rrun() == 2)
  if(!wait(100)) return;  // wait until computation is finished or [Stop] was hit
while(some_long_loop) {
  if(!wait(-1000)) break; // prevent unresponsiveness in long loops

See also:

timer, run, R bridge, lock, BUSY, quit, version, progress, suspended, call

► latest version online