You can commit errors and warnings with the argument type="message" before capture.output . type can be either "output", which captures the output of the function, or "message", which captures errors and warnings. The function below uses sapply so that you can run capture.output once with each argument, storing the results in a list.
capture.errors = function(type, data) { sapply(type, function(type) { capture.output(auto.arima(data), type=type) }, simplify=FALSE) } out = capture.errors(c("output","message"), testseries) out $output [1] "Series: data " [2] "ARIMA(0,0,0) with non-zero mean " [3] "" [4] "Coefficients:" [5] " intercept" [6] " 834.6000" [7] "se 42.4746" [8] "" [9] "sigma^2 estimated as 9020: log likelihood=-29.86" [10] "AIC=63.73 AICc=69.73 BIC=62.94" $message [1] "Error in arima(x, order = c(1, d, 0), xreg = xreg) : " [2] " non-stationary AR part from CSS" [3] "In addition: Warning message:" [4] "In auto.arima(data) : Unable to calculate AIC offset"
Since capturing model output using capture.output is probably not as useful as capturing βrealβ output in a model object, the function below might be better. It returns a list with the model object and any error or warning messages:
capture = function(data) { list(model=auto.arima(data), message=capture.output(auto.arima(data), type="message")) }
The model object is accessible in the usual way, so below I just look at the output of the message.
out1 = capture(testseries) # Show any errors and warnings out1[["message"]] [1] "Error in arima(x, order = c(1, d, 0), xreg = xreg) : " [2] " non-stationary AR part from CSS" [3] "In addition: Warning message:" [4] "In auto.arima(data) : Unable to calculate AIC offset" out2 = capture(cumsum(rnorm(100))) # No errors or warnings with this data set out2[["message"]] character(0)