Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to temporarily supress warnings in R

Tags:

r

Currently I write:

warn = getOption("warn")
options(warn=-1)
foo()
options(warn=warn)

Is there a better solution?

like image 870
user31264 Avatar asked Apr 07 '16 11:04

user31264


People also ask

What is suppressWarnings R?

suppressWarnings evaluates its expression in a context that ignores all warnings.

What is suppressPackageStartupMessages?

suppressPackageStartupMessages() method in R language can be used to disable messages displayed upon loading a package in R. This method is used to suppress package startup messages. The package should be pre-installed in R, otherwise, a warning is displayed upon function call.


2 Answers

Use suppressWarnings():

suppressWarnings(foo())
like image 194
Thomas Avatar answered Sep 18 '22 20:09

Thomas


You wrap an expression in suppressWarnings() (yet here foo() returns an error, not a warning).

like image 36
Vincent Bonhomme Avatar answered Sep 18 '22 20:09

Vincent Bonhomme