I have a large R script of, say, 142 small sections. If one section fails with an error I'd like the script to continue rather than halt. The sections don't necessarily depend on each other, but some do. If one in the middle fails that's ok. I'd prefer not to pepper this script with try()
calls. And I'd prefer not to have to split the file up into many smaller files as each section is quite short.
If source()
could be made to work as if it had been copy and pasted at the R console, that would be great. Or if there was a way to downgrade error to warning, that would be fine too.
Once the script has run I intend to grep (or similar) the output for error or warning text so that I can see all the errors or warnings that have occurred, not just that it has halted on the first error.
I've read ?source
and searched Stack Overflow's [R] tag. I found the following similar questions, but try
and tryCatch
were the answers provided :
R Script - How to Continue Code Execution on Error
Is there any way to have R script continue after receiving error messages instead of halting execution?
I'm not looking for try
or tryCatch
for the reasons above. This isn't for R package testing, where I'm aware of the testing frameworks and where many try()
or test_that()
calls (or similar) are entirely appropriate. This is for something else where I have a script as described.
Thanks!
See Question&Answers more detail:os