How to change warning setting?

六月ゝ 毕业季﹏ 提交于 2019-11-30 12:38:19

问题


I am trying to debug a function. I would like to display warnings when they occur but I don't understand how to change the warning settings.


回答1:


Set

options(warn=1)

Read more in ?options




回答2:


It may be useful to specify

options(warn=2, error=recover)

As mentioned by @plannapus, warn=2 will upgrade warnings to errors; error=recover will drop you into a debug/browser mode at the point where the warning (now upgraded to an error) occurred. (Use options(warn=0, error=NULL) to restore the original settings.)




回答3:


From the help page for options :

warn: sets the handling of warning messages. If warn is negative all warnings are ignored. If warn is zero (the default) warnings are stored until the top–level function returns. If fewer than 10 warnings were signalled they will be printed otherwise a message saying how many (max 50) were signalled. An object called last.warning is created and can be printed through the function warnings. If warn is one, warnings are printed as they occur. If warn is two or larger all warnings are turned into errors.

So options(warn=1) should print warnings as they occur.

Otherwise function traceback() (after an unidentified error) shows you which subroutine failed (more exactly "the sequence of calls that lead to the error").



来源:https://stackoverflow.com/questions/11239428/how-to-change-warning-setting

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