张兵
R 无视错误继续执行代码 option(error=...)
2023-4-10 13:17
阅读:1040

http://web.mit.edu/r/current/lib/R/library/base/html/options.html

  • error:

  • either a function or an expression governing the handling of non-catastrophic errors such as those generated bystop as well as by signals and internally detected errors.  If the option is a function, a call to that function, with no arguments, is generated as the expression.  The default value is NULL: see stop for the behaviour in that case.  The functions dump.frames andrecover provide alternatives that allow post-mortem debugging.  Note that these need to specified as e.g. options(error = utils::recover) in startup files such as ‘.Rprofile’.

# 在访问某些网站时,可能超时,出现错误。这时R无法继续执行下面的代码。

# 需要跳过错误,继续运行下面的代码。可以设置option(error=...)
# Will continue to execute script even after error, when options()$error is not NULL
options(error = function(){cat('continue to execute script even after error.\n')})

转载本文请联系原作者获取授权,同时请注明本文来自张兵科学网博客。

链接地址:https://wap.sciencenet.cn/blog-331295-1383646.html?mobile=1

收藏

分享到:

当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?