I'm really at a loss here. I found a couple of threads here on stack overflow on how to redirect the output of a function, but none of it seems to be working in my case.
I'm using arima from the library(forecast)
for a lot of (generated) timeseries, and some of them have bad properties, which results in auto.arima()
printing out an error and a warning. I'm unable to catch this Error in anyway, be it via tryCatch
or capture.output()
(which only captures the normal forecast).
The goal is to capture the error message (and warning) thrown by the example below and react to it. So basically at the end i would have the error and the forecast (despite being errorneous) in some variable form.
I appreciate any suggestions, the following is the minimal example to produce the error:
library(forecast)
testt <- c(826,816,839,995,697)
testend <- c(2015,164)
testseries <- ts(testt,end=testend,frequency=365)
auto.arima(testseries)
#tryCatch not working:
testfc <- tryCatch(forecast(auto.arima(testseries),h=1), error=function(e) NA)
#capture.output not working:
result <- capture.output(auto.arima(testseries))