I would like to program a time series class. The idea is that I create an instance of an object with an expression and some other time series objects, for example
(two time series)
x <- ts(rnorm(10), frequency = 4, start = c(1959, 2))
y <- ts(rnorm(10), frequency = 4, start = c(1959, 2))
(time series defined as the sum of x and y)
z <- exprTs("x+y", parents=list(x=x, y=y))
(get part of the series)
window(z, start=1960, end=1960.75)
The problem is, how can I evaluate the expression? I tried the following:
exprTs <- function(expr, parents) {
res = list(expr=expr, parents=parents)
class(res) <- "exprTs"
res
}
window.exprTs <- function(z, ...) {
eval(substitute(z$expr, lapply(z$parents, window, ...)))
}
I cannot get the window method to work.
If you could guide me on how to use substitute, eval, do.call accordingly, that would be very helpful.