0 votes
1 view
in R Programming by (6.5k points)

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?

2 Answers

0 votes
by (25.3k points)
edited by
 
Best answer

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

options(warn=-1)

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

defaultW <- getOption("warn") 

options(warn = -1) 

[YOUR CODE] 

options(warn = defaultW)

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

0 votes
by (33.2k 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)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...