Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Suppress Warnings Globally in R

  • Last Updated : 31 Aug, 2021

In this article, we are going to discuss how to suppress warnings globally in R programming language.

A warning is a message that does not disturb the program flow but displays the warning along with the output. In order to suppress the warnings globally, we have to set warn=-1 in the options function

Syntax:

options(warn = – 1)   

If you want to see the warnings then set warn=0

Example: R program to see the warning when using pmax and pmin

R




# pmax function and display the warnings
# pmax function will return the parallel
# maximum of two vectors
pmax(c(1, 2, 3), c(1, 2, 3, 4, 5))
  
# pmin function and display the warnings
# pmin function will return the parallel
# minimum of two vectors
pmin(c(1, 2, 3), c(1, 2, 3, 4, 5))

Output:

Example: R program to suppress the warning messages when using pmax and pmin

R




# suppress the warnings by setting warn=-1
options(warn=-1)
  
# pmax function and display the warnings
# pmax function will return the parallel
# maximum of two vectors
pmax(c(1, 2, 3), c(1, 2, 3, 4, 5))
  
# pmin function and display the warnings
# pmin function will return the parallel
# minimum of two vectors
pmin(c(1, 2, 3), c(1, 2, 3, 4, 5))

Output:

12345
12312

If we want to see the warnings again, set warn=0

Example: R program to again see the warnings

R




# display the warnings by setting warn=0
options(warn=0)
  
# pmax function and display the warnings
# pmax function will return the parallel
# maximum of two vectors
pmax(c(1, 2, 3), c(1, 2, 3, 4, 5))
  
# pmin function and display the warnings
# pmin function will return the parallel
# minimum of two vectors
pmin(c(1, 2, 3), c(1, 2, 3, 4, 5))

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!