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 ( c (1, 2, 3), c (1, 2, 3, 4, 5))
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
options (warn=-1)
pmax ( c (1, 2, 3), c (1, 2, 3, 4, 5))
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
options (warn=0)
pmax ( c (1, 2, 3), c (1, 2, 3, 4, 5))
pmin ( c (1, 2, 3), c (1, 2, 3, 4, 5))
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...