Skip to content
Prev 244116 / 398506 Next

Time out for a R Function

Below is a toy function with one way of doing it. There are bound to
be better ways :)

function(niter = 10, time.out = 3) {
  pretend.task <- function() {
  	Sys.sleep(0.5)
  }

  start <- proc.time()

  for (iter in 1:niter) {
    pretend.task()	
    cur <- proc.time() - start
    if (cur[3] > time.out) return("timed out")
  }

  return("completed")
}
On 7 December 2010 13:04, Santosh Srinivas <santosh.srinivas at gmail.com> wrote: