Suppress Warnings Globally in R (Example)
In this R tutorial you’ll learn how to disable warning messages in the global options.
Table of contents:
Let’s dive right into the examples…
Example: Disable Warning Messages in R
I’ll illustrate the suppression of warning messages in R based on the pmax function. Consider the following R code:
pmax(1:3, 1:5) # pmax function returns warning # [1] 1 2 3 4 5 # Warning message: # In pmax(1:3, 1:5) : an argument will be fractionally recycled
As you can see, the pmax function returns a warning message to the RStudio console.
We can suppress this warning message by running the following R syntax:
options(warn = - 1) # Disable warning messages globally
The previous R code specifies globally that warnings are never returned to the RStudio console.
Let’s illustrate that based on the pmax function. If we run exactly the same R code as before, no warnings are returned:
pmax(1:3, 1:5) # pmax function without warnings # [1] 1 2 3 4 5
Set Global Options to Default
In case you want to turn on warning messages again, you can set the global R options for warnings back to default as shown below:
options(warn = 0) # Set warning messages to default
Let’s run our exemplifying pmax function once more:
pmax(1:3, 1:5) # pmax function returns warning again # [1] 1 2 3 4 5 # Warning message: # In pmax(1:3, 1:5) : an argument will be fractionally recycled
The warning message is back!
Video & Further Resources
Do you need further explanations on the R programming syntax of this article? Then you may watch the following video tutorial of my YouTube channel. I’m explaining the examples of this article in the video.
In addition, I can recommend reading some of the related tutorials of my website.
Summary: In this article, I showed how to clear and ignore warnings in the R programming language. Please let me know in the comments section, in case you have any additional questions.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






