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

Duncan Murdoch murdoch at stats.uwo.ca
Wed Apr 2 18:17:24 CEST 2008


On 4/2/2008 12:00 PM, Lukas Rode wrote:
> Dear Bert and Mel,
> 
> thanks for your help, but I'm afraid this doesn't solve my problem.
> 
> As I wrote in my previous mail (cf quote below) in most cases I will not be
> able to modify the code of the function that I want to run. This is why I
> was asking for a wrapper solution similar to what tryCatch does. I have
> hinted at a very inelegant version that generates a new R process for each
> function run and kills the process after a given time. But I'm sure there
> must be something more elegant. I hope I have been clear enough in my
> problem description.

On some systems (not Windows) you could ask some external process to 
send a signal after a certain time interval, and I believe you can write 
you code to recover afterwards.  I don't know any reasonable way to do 
this on Windows.

Duncan Murdoch

> 
> Thanks again,
>   Lukas
> 
> Here is what I wrote before:
> 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.
> 
> 
> 
> On Wed, Apr 2, 2008 at 5:23 PM, mel <mel at altk.com> wrote:
> 
>> 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
>>
>> ______________________________________________
>> 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.
>>
> 
> 	[[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.



More information about the R-help mailing list