0

I created a task running each hour by taskscheduleR. However, it may have some local connection problem and go to infinite loop. Since taskscheduleR detects R script is still working, next task doesn't start.

I am looking a way if execution of R script lasts more than 10 min, interrupt this task.

When I click on the exit button, it stops the execution. This schedule is created in a common PC. Thus, it should be stopped automatically.

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • look up `?tryCatch` – GWD Jun 28 '20 at 14:38
  • [`?setTimeLimit`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/setTimeLimit.html). Similarly, you can also address the "infinite loop" risk by counting in your loop, something like `iter <- 30; while (iter > 0) { iter <- iter - 1; ...; }`. After the loop completes, if the value of `iter` is 0 then you looped-out and did not complete successfully. – r2evans Jun 28 '20 at 16:45
  • Before starting your loop, you can get the system time `start <- Sys.time()` and assign `time_passed <- 0` then at the end of your loop, calculate the time difference `time_passed <- Sys.time() - start ` . Finally use `break` etc. if the `time_passed >600`, or you can pass it in a while loop with your other contitions like `while(sth & time_passed <=600) { .... }` _(600 is standing for 10 minutes)_ – maydin Jun 28 '20 at 17:00

0 Answers0