0

I want to capture the input and output of R into a separate text file. I found that the best way to do so is a combination of sink() and source() commands (How to save all console output to file in R?).

My problem is that in some data constellations, I get error messages. The exeution of the script via source() seems to stop right after an error occurs. However, I would like to run the script to the end and simply record everything, including the errors.

How can I adapt my approach to "skip" errors?

deca
  • 730
  • 1
  • 8
  • 24

1 Answers1

0

You have to use tryCatch() for every error.

For example,

tryCatch({
    print('This line works well');
    stop('that line contains an error')
}, error = function(e){})
Zhuoer Dong
  • 629
  • 4
  • 11