[R] Variable scope.
rkevinburton at charter.net
rkevinburton at charter.net
Sun Mar 1 03:26:59 CET 2009
I have a question on scope/reference/value type of variables with 'R'.
The issue cam up first when I look at the arima code.
I see code like:
myupARIMA <- function(mod, phi, theta) {
. . . .
mod
}
Then
armafn <- function(p, trans) {
. . . .
Z <- upARIMA(mod, trarma[[1]], trarma[[2]])
. . . .
res <- .Call(R_ARIMA_Like, x, Z$phi, Z$theta, Z$Delta,
Z$a, Z$P, Z$Pn, as.integer(0), FALSE)
. . . .
}
The question is that ARIMA_Like will make changes to the arrays Z$P etc. Since upARIMA essentially returns 'mod' are changes to the arrays passed as Z$... to ARUINA_Like refkected in the original 'mod'? Or another way of phrasing the question is 'Z' a reference variable? Are the members such as Z$a also passed as reference hence changes to Z$a should also be seen in mod$a? In the arima code the references to x and mod seem to be essentially global variables as armafn is 'nested' in arima. Will changes to x also be reflected in the original x? (Like x <- x - (xreg %*% par[narma + (1:ncxreg)))
Thank you.
Kevin
More information about the R-help
mailing list