0

So I have an R script (Master.R) which calls another R script (minor.R) and I want to be alerted to when the minor.R errors out.

I tried to follow the suggestion in R Script - How to Continue Code Execution on Error, but it isnt returning anything when the script errors.

R script master:

# run minor.R
res1 = try({system(paste("Rscript minor.R", var1))})
if(inherits(res1, "try-error")){
         print("Hey, a warning")
}

I also tried

tryCatch({system(paste("Rscript minor.R", var1))},
         error = function(e) {print("Hey, a warning")})

But no luck, when the code errors it does not return the phrase.

How can I catch the error and get it to execute a subsequent piece of code?

Laurence_jj
  • 646
  • 1
  • 10
  • 23
  • If I run `tryCatch({system(paste("Rscript minor.R", var1))}, error = function(e) {print("Hey, a warning")})` as it is and since I don't have that script it returns me the phrase as expected. – Ronak Shah Jan 31 '20 at 10:14
  • I suspect that it because the script does not run, however what happens if the script does run but then errors out? In my case no error is returned. – Laurence_jj Jan 31 '20 at 10:44
  • I found that if I put the tryCatch statement round the whole `minor.R` script then that worked instead. I think the error is not being passed to `master.R`. – Laurence_jj Jan 31 '20 at 11:24

0 Answers0