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?