[R] Stopping a function execution automatically after a given time

mel mel at altk.com
Wed Apr 2 17:23:56 CEST 2008


Lukas Rode a écrit :

> Nowever, with regard to #2, I am lost. I would like to set a maximum time
> limit (say, 1 minute) and if my procedure is still running then, I would
> like to move on to the next model.


begin_time = as.difftime(format(Sys.time(), '%H:%M:%S'), units='secs');
for(...)
  {
  ...
  current_time = as.difftime(format(Sys.time(), '%H:%M:%S'), units='secs');
  delay = current_time - begin_time;
  if (delay>60) return();
  }

a counter may also be enough



More information about the R-help mailing list