0

I have an R script code.R that has a certain probability of throwing an error. A layman example of such script could be:

if(runif(1,1,5)>2){
  stop("Shift happens")
}else{cat("\nGreat success!")}

At this point, I am just manually calling the script several times in terminal until it has finished without throwing an error, like this:

Rscript /path_to_script/code.R 

How can I run an Rscript in Linux until it has finished without throwing an error?

Nikolay Nenov
  • 547
  • 1
  • 8
  • 27
  • 1
    If your script was just `stop("Big Fail")` then it would never finish without throwing an error (probability of error =1). Would you just want to run it forever? Also, is there a reason you don't want to catch the error in your R code and re-run the command there? Do you really need to accomplish this in your linux shell? – MrFlick Apr 03 '19 at 15:37
  • 1
    IMO it's R, not linux problem. You can try adding `while` condition. *while (if (condition) {operation})* – pogibas Apr 03 '19 at 15:38
  • 1
    @MrFlick I'm answering your questions in the order you asked them: No. No. and No :) – Nikolay Nenov Apr 03 '19 at 15:49
  • @PoGibas that's an option I guess. Consider suggesting a working solution, and I will be happy to accept it. – Nikolay Nenov Apr 03 '19 at 15:50
  • 1
    See this question for a way to re-run R code on error. It also has a max attempts option: https://stackoverflow.com/questions/20770497/how-to-retry-a-statement-on-error – MrFlick Apr 03 '19 at 17:03
  • Awesome, that solves my question. Thanks a lot! – Nikolay Nenov Apr 04 '19 at 07:55

0 Answers0