So, I am trying to understand scope and functionality of tryCatch in R.
the following line:
arima(rep(1,3), order = c(1,0,0))
generates both warning and error, however in tryCatch block only warning function returns value. How can I get access to return value of both warning and error?
tryTest = tryCatch(
{
arima(rep(1,3), order = c(1,0,0))
},
warning = function(w) {
print('this is warning')
print(w)
return('return string from warning')
},
error = function(e) {
print('this is error')
print(e)
return('return string from error')
},
finally = {}
)
print(tryTest)
produces only:
"return string from warning"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…