【问题标题】:How to return a error message in R?如何在 R 中返回错误消息?
【发布时间】:2012-09-25 06:49:48
【问题描述】:

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

【问题讨论】:

  • 这不是@petermeissner 问题的确切答案(这就是我在这里发表评论的原因),但在这种情况下肯定经常被忽视和帮助:geterrmessage() 返回最后一条错误消息,使您能够传递来自其他函数(在您自己的函数中使用)的错误消息。与tryCatch 一起使用时非常有用。

标签: r


【解决方案1】:

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

?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.

【讨论】:

    【解决方案2】:

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

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

    stop("This is an error message")
    

    【讨论】:

      猜你喜欢
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 2023-02-03
      • 1970-01-01
      • 2014-05-01
      • 2012-03-20
      • 1970-01-01
      相关资源
      最近更新 更多