如何在R中返回错误消息?

时间:2012-10-04 09:02:35

标签: r

我想知道如何在R中生成错误消息,特别是在函数中?

2 个答案:

答案 0 :(得分:74)

由于你没有指明你真正想要的东西,我只能说看看

?message # prints a message but not stop execution
?warning # prints a warning message but not stop execution
?stop # stops execution of the current expression and executes an error action.

答案 1 :(得分:2)

只需在函数/脚本中包含stop()

如果您希望收到错误消息,请像这样将其包含在stop()

stop("This is an error message")