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

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Wed, 02 Apr 2008 08:16:52 -0700

?help.search("time")
?proc.time
?system.time

You can stick these in your code appropriately to keep track of elapsed time. You could also count iterations, of course.

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Lukas Rode
Sent: Wednesday, April 02, 2008 8:07 AM
To: r-help_at_stat.math.ethz.ch
Subject: [R] Stopping a function execution automatically after a given time

Dear all,

I often need to execute functions repeatedly (thousands or more times). While doing so, I encounter two types of problems:

1.) In some models, the estimation process fails due to convergence problems 2.) Some models will run forever.

My solution to #1 is to use tryCatch around the function call so that my script does not stop if one of the models will raise an error. This works fine.

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.
I guess a brute-force solution would be to start a new R process for each model from my R script and to kill the process using system commands after a given time. However, restarting the R interpreter each time sounds very inelegant. Are there any versions that work within a single script? Or alternative suggestions?

Note that mostly these functions are not written by me and not R code (like nlme for example), so it is not feasible to adapt the function itself. Rather, it needs to be a wrapper around the function, similar to tryCatch.

Any help appreciated!
Kind regards,
  Lukas

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 02 Apr 2008 - 15:34:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Apr 2008 - 16:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive