Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: how to clear all warnings

Tags:

r

warnings

I would like to clear the warnings() list using a command line.

I have tried with no success

> rm(last.warning, envir = baseenv())  
Error in rm(last.warning, envir = baseenv()) :   
cannot remove variables from the base environment

any idea?

like image 677
RockScience Avatar asked Apr 20 '11 03:04

RockScience


People also ask

How do I turn off error messages in R?

As suggested by the previous solution, you can use try or tryCatch functions, which will encapsulate the error (more info in Advanced R). However, they will not suppress the error reporting message to stderr by default. This can be achieved by setting their parameters. For try , set silent=TRUE .

What is suppressWarnings R?

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


3 Answers

Try assign("last.warning", NULL, envir = baseenv())

like image 193
Joshua Ulrich Avatar answered Oct 20 '22 20:10

Joshua Ulrich


Take a look at suppressWarnings() to stop the warnings from showing up.

Notice in the help page for warnings that it says:

"....It is undocumented where last.warning is stored nor that it is visible, and this is subject to change. Prior to R 2.4.0 it was stored in the workspace, but no longer...."

like image 26
bill_080 Avatar answered Oct 20 '22 18:10

bill_080


I agree, I want to use a try() and gather up just the warnings generated by that try().

My solution for now is

assign("last.warning", NULL, envir = baseenv())
    myFit  <- try(...)
    warned <- warnings()
assign("last.warning", NULL, envir = baseenv())
like image 41
BWMorlan Avatar answered Oct 20 '22 19:10

BWMorlan