【发布时间】:2012-09-25 06:49:48
【问题描述】:
我想知道如何在 R 中产生错误消息,尤其是在函数内部?
【问题讨论】:
-
这不是@petermeissner 问题的确切答案(这就是我在这里发表评论的原因),但在这种情况下肯定经常被忽视和帮助:
geterrmessage()返回最后一条错误消息,使您能够传递来自其他函数(在您自己的函数中使用)的错误消息。与tryCatch一起使用时非常有用。
标签: r
我想知道如何在 R 中产生错误消息,尤其是在函数内部?
【问题讨论】:
geterrmessage() 返回最后一条错误消息,使您能够传递来自其他函数(在您自己的函数中使用)的错误消息。与tryCatch 一起使用时非常有用。
标签: r
由于你没有具体说明你真正想要什么,我只能说看看
?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.
【讨论】:
只需在您的函数/脚本中包含stop()
如果您想要一条错误消息,请将其包含在 stop() 中,就像这样
stop("This is an error message")
【讨论】: