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

From: Lukas Rode <lukas.rode_at_googlemail.com>
Date: Wed, 02 Apr 2008 17:06:59 +0200


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. Received on Wed 02 Apr 2008 - 15:09:29 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