My code contains a command which is essential for it to run, however it ends up showing the result of this command in the console, i have tried to use suppressWarnings(), suppressMessages(), invisible() and sink() but all of these still show the result.
Here is an example data set and where the problem originates from:
M<-c(1111,1222,1333,1444,1555,1666,1777,2223,6654,9867,1123,1456,2436,6875)
fstAdi <- ets(ts(rep(M,length = length(M)), deltat= 1/4, start = c(8,1)), model = "AAA", damped = FALSE, opt.crit = "mae", ic="aic", lower = c(0, 0, 0, 0), upper = c(0.999, 0.999, 0.999, 0.999), bounds = "admissible", restrict = FALSE)
mae11Ad<-summary(fstAdi)[,"MAE"]
The last line of the code above always shows the summary in the console, which when automating this for a report causing problems. Does anyone know of a command which can stop this happening?
Thankyou
I have found a way to hide it while automating the report, but if anyone knows how to hide it while just running the code to make the process quicker then that would be really helpful anyway :)
The summary method for ets objects is a bit verbose:
> forecast:::summary.ets
function (object, ...)
{
print(object)
cat("\nTraining set error measures:\n")
print(accuracy(object))
}
<bytecode: 0x161d31c8>
<environment: namespace:forecast>
This is pretty bad style, summary methods should return an object with a class and the print method for that class should produce the output.
So you could just call the accuracy method on your object:
> accuracy(fstAdi)[,"MAE"]
[1] 1971.468
which has the advantage of not needing any diversion of output and is more readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With