相当于“抛出”在R [英] Equivalent of "throw" in R

查看:77
本文介绍了相当于“抛出”在R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在R中抛出错误?我有一个函数需要一个数据框和一些列名,并与它们进行填充。如果列不存在,我希望该功能停止,并根据它停止所有功能。



我看过恢复浏览 traceback 但是,他们似乎很接近但不是我正在寻找的。

解决方案

请参阅 help(tryCatch)



' signalCondition '。另外,

'停止'和'警告'功能有
被修改为也可以接受

条件参数。


后面的另请参见:


'停止'和'警告 '信号条件'和' try '本质上是一个
简化版的' tryCatch '。 p>

所以你可能想要 stop


How does one "throw" an error in R? I have a function that takes a data frame and some column names and does stuff with them. If the columns don't exist, I want the function to stop and to stop all functions depending on it.

I have looked at recover and browse and traceback but, well, they seemed to be close but not what I am looking for.

解决方案

See help(tryCatch):

Conditions are signaled by 'signalCondition'. In addition, the
'stop' and 'warning' functions have been modified to also accept
condition arguments.

and later under 'See Also':

'stop' and 'warning' signal conditions, and 'try' is essentially a simplified version of 'tryCatch'.

so you probably want stop.

这篇关于相当于“抛出”在R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆