R:如何清除所有警告
我想使用命令行清除 warnings() 列表。
我尝试过但没有成功,
> rm(last.warning, envir = baseenv())
Error in rm(last.warning, envir = baseenv()) :
cannot remove variables from the base environment
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试分配(“last.warning”,NULL,envir = baseenv())
Try
assign("last.warning", NULL, envir = baseenv())
只是为了强调上面@Richie Cotton提到的内容(帮助页面现在不再提到2.4.0,但是):这实际上不是推荐,即使它已被接受的答案在这里。
相反,您应该使用更强大的错误处理程序工具,特别是对于上面的 @BWMorlan 的情况,您可以使用 - 多次“广告”
tryCatch.WE()
实用程序函数,它捕获所有警告和错误,并在没有错误时使用 R 中的
demo(error.keeping)
获取该函数并在中查看它行动,或
获取评论来源。
Just to emphasize what @Richie Cotton mentioned above (the help page now no longer mentions 2.4.0, but): This is
assign("last.warning", envir = baseenv())
is really not recommended even though it's been the accepted answer here.Rather, you should use the much more powerful error handler tools, notably for @BWMorlan's case above, you could use the - several times "advertized"
tryCatch.WE()
utility function which catches all warnings and errors and provides results when not errorusing
demo(error.catching)
in R to get the function and see it in action,or
to get the commented source.
看看
suppressWarnings()< /code>
停止显示警告。
警告帮助页面中的通知它说:
Take a look at
suppressWarnings()
to stop the warnings from showing up.Notice in the help page for warnings that it says:
我同意,我想使用 try() 并仅收集该 try() 生成的警告。
我现在的解决方案是
I agree, I want to use a try() and gather up just the warnings generated by that try().
My solution for now is
只需使用“警告(立即。= FALSE)”
例如
Simply use 'warning(immediate. = FALSE)'
E.g.