相当于“投掷"在 R [英] Equivalent of "throw" in R

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

问题描述

如何在 R 中抛出"错误?我有一个函数,它接受一个数据框和一些列名,然后用它们做东西.如果列不存在,我希望该函数停止并根据它停止所有函数.

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.

我已经查看了 recoverbrowsetraceback 但是,好吧,它们似乎很接近,但不是我想要的.

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

推荐答案

查看help(tryCatch):

条件由'信号条件'.此外,
'stop' 和 'warning' 函数有已修改为也接受
条件参数.

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' 和 'warning' 信号条件,而 'try' 本质上是一个'tryCatch' 的简化版.

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

所以你可能想要stop.

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

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