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

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed, 02 Apr 2008 12:17:24 -0400

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.


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 - 16:18:09 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 - 18:30:26 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