I'm creating unit tests on the forecast package, specifically for the 
forecast.ar() function. I have a block of code that works just fine when run on 
its own.

require(testthat)
require(forecast)
set.seed(55)
simseries <- stats::arima.sim(model = list(ar = c(-0.42, 0.832, 0.1, -0.34)), n 
= 400)
arfit <- stats::ar(simseries)
fc1 <- forecast(arfit)$mean
fc2 <- forecast(arfit, bootstrap = TRUE, npaths = 100, fan = TRUE)$mean
expect_true(all(fc1 == fc2))

However, when I embed this in a test_that() function (after starting a new 
clean R session), I get an error that the ts is empty. I've determined that the 
error occurs on the two lines generating fc1 and fc2; simseries is assigned 
correctly.

require(testthat)
require(forecast)
test_that("tests for forecast.ar", {
set.seed(55)
simseries <- stats::arima.sim(model = list(ar = c(-0.42, 0.832, 0.1, -0.34)), n 
= 400)
arfit <- stats::ar(simseries)
fc1 <- forecast(arfit)$mean
fc2 <- forecast(arfit, bootstrap = TRUE, npaths = 100, fan = TRUE)$mean
expect_true(all(fc1 == fc2))
})

Why is this happening? I thought it might be a namespace issue with using the 
ar and arima.sim functions from the stats package, so I included the stats 
namespace in the function call, but that does not fix the problem.

R 3.1.1 forecast 6.1 testthat 0.10.0

David Shaub
Business Operations Analyst II
In-Home Services |Dish Network L.L.C
IHS Command Center | Forecasting Team
david.sh...@dish.com<mailto:gavin.redel...@dish.com>



        [[alternative HTML version deleted]]

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to