How to suppress warnings globally in an R Script

Richard picture Richard · Apr 24, 2013 · Viewed 202.3k times · Source

I have a long R script that throws some warnings, which I can ignore. I could use

suppressWarnings(expr)

for single statements. But how can I suppress warnings in R globally? Is there an option for this?

Answer

sieste picture sieste · Apr 24, 2013

You could use

options(warn=-1)

But note that turning off warning messages globally might not be a good idea.

To turn warnings back on, use

options(warn=0)

(or whatever your default is for warn, see this answer)