R: how to clear all warnings

隐身守侯 提交于 2020-12-27 07:46:21

问题


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?


回答1:


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




回答2:


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...."




回答3:


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())


来源:https://stackoverflow.com/questions/5725106/r-how-to-clear-all-warnings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!