Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (7.3k points)

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


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


2 Answers

+1 vote
Best answer

To suppress warnings in the global settings, you can use the warn option in options function as follows:


To temporarily suppress warnings in global settings and turn them back on, use the following code:

defaultW <- getOption("warn") 

options(warn = -1) 


options(warn = defaultW)

If you want to explore more in R programming then watch this R programming tutorial for beginner:

0 votes
by (33.1k points)

You want options(warn=-1). But, note that warn=0 is not the safest warning level and it should not be assumed as the current one, particularly within scripts or functions. Thus the safest way to temporary turn off warnings is:

oldw <- getOption("warn")

options(warn = -1)

[your "silenced" code]

options(warn = oldw)

Hope this answer helps you!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 10, 2019 in R Programming by Ajinkya757 (5.3k points)

Browse Categories