mat <- large matrix
f1 <- function(M) {
X <<- M
f1 <- function() {
do something with X but does not modify it
}
}
f1(mat)
X is no longer in scope
How does one achieve what is described in the pseudocode above in R? In MATLAB, you can use "global X". What is the equivalent in R? If there is none, what is the most efficient way to deal with the scenario above: a function takes in a large matrix as an argument and many different helper function within it act on that matrix (but do not modify it) thus the matrix needs to be copied as few times as possible. Thanks for your help.