Given a function which calls a function, e.g.
topfun <- function(x){
y = 1:1e6
result <- botfun(x,y)
}
botfun <- function(x,y) return x * sum(y)
Versus, perhaps,
topfun <- function(x){
y = 1:1e6
result <- botfun(x)
}
botfun <- function(x) {
return(x + sum(get('y',envir = parent.frame()))
}
How many copies of y
are created in each case (if any)? Are there other memory or execution-time concerns? Or, for that matter, am I going at this in a naive way?