【问题标题】:using tryCatch in a loop for bnets在 bnets 的循环中使用 tryCatch
【发布时间】:2016-09-13 10:27:21
【问题描述】:

我正在尝试使用 tryCatch 循环一个我知道会产生错误的函数,但我无法获得正确的错误语法。

xcount <- 1
while(xcount < 11){
xvar <- as.character(x[,xcount])
yvar <- as.character(x[,xcount+1])
bn <- set.arc(bn, xvar, yvar)
for(bn in 1:11){
tryCatch({
plot(bn)
score(bn, foo)
error= function(e)
print('error')})}

【问题讨论】:

    标签: r try-catch


    【解决方案1】:

    您的tryCatch 语法已关闭。改用这个:

    tryCatch({
        print(bn)
    }, error = function(e) {
        print('error')
    })
    

    这是一个great reference,展示了如何在 R 中使用tryCatch

    【讨论】:

      猜你喜欢
      • 2015-06-01
      • 2018-10-02
      • 2020-03-23
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 2017-06-07
      相关资源
      最近更新 更多