63

我想知道如何能够在 R 中产生错误消息,尤其是在函数内部?

4

2 回答 2

117

既然你没有具体说明你真正想要什么,我只能说看看

?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.
于 2012-10-04T09:04:10.117 回答
32

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

如果您想要一条错误消息,请stop()像这样将其包含在内

stop("This is an error message")
于 2019-04-04T15:59:00.547 回答