2016-09-13 121 views
0

我想使用tryCatch循環一個函數,我知道會產生錯誤,但我不能得到正確的錯誤語法。使用TryCatch在一個循環bnets

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')})} 

回答

0

您的tryCatch語法已關閉。使用這個來代替:

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

這裏是展示瞭如何在R.

使用 tryCatch一個 great reference