1

I'm using sendmailR in my R script to send notifications.

Sometimes notification fails with the following error:

Unknown SMTP code: 452
Error in if (code == lcode) { : argument is of length zero

Execution halts.

How can I handle such errors, so that even if notification fails the script runs on?

Mikhail
  • 1,326
  • 6
  • 22
  • 29

1 Answers1

2

Wrap the try function around sendmail (assuming you use sendmail, if not then wrap it around the function or code that produces the error) this way:

 try(sendmail(from,to,subject), silent=T)

You can set silent to FALSE if you want the error message to appear but still continue with the process

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
  • 1
    I'd rather use `tryCatch`, so that you can react on the error message, but more importantly: don't be lazy to write `TRUE` instead of an uppercase `t`, as strange things can happen :) – daroczig Mar 05 '15 at 04:28