this question is somewhat a follow up on this question.
Consider the following example
set.seed(1) x <- cumsum(rnorm(10)) y <- stats::arima(x, order = c(1, 0, 0)) length(stats::fitted(y))  0
So far so good: zero is returned because R does not now how to use
stats::fitted on an object of class
Next in my code, I need one function from the
forecast package. I do not attach the package, I just load it using the
In my code below I will load it directly using
requireNamespace("forecast", quietly = TRUE) length(stats::fitted(y))  10
And suddenly the same command returns a different result.
I understand why this happens (and I hope I am saying it correctly): by loading the
forecastpackage a new method for the generic function
fitted.Arima) is loaded into the namespace which results in a different outcome.
For me this behavior is quite annoying: is there any way to choose on specific method for
I read this chapter but did not figure out how to circumvent this problem.
I also tried to unload the
forecast package from namespace, but no success:
unloadNamespace("forecast") length(stats::fitted(y))  10
It seems that once I load the package I cannot use the old method of
I am wondering how to handle these situations.
As pointed out in the comments after
unloadNamespace("forecast") I get that
isNamespaceLoaded("forecast")  FALSE
methods fitted still includes