[R] Call by reference or suggest workaround
Chidambaram Annamalai
quantumelixir at gmail.com
Sat Jun 19 16:32:42 CEST 2010
I have written code to compute multi-indices in R [1] and due to the
recursive nature of the computation I need to pass around the *same*
matrix object (where each row corresponds to one multi-index). As pass
by reference wasn't the default behavior I declared a global matrix
(mat) and used the <<- operator to write to the global matrix. So the
usage would be to call genMultiIndices(3,2) for side effects to
generate all multi-indices of length 3 and sum 2. And then access the
global matrix.
However, after coding this I can't seem to export the global matrix
object (in the NAMESPACE file) and still retain mutability since its
binding is "locked" (R throws an error). Can I somehow unlock this?
Ideally I would want to pass around the same matrix to the recursive
function. Is that possible? If not, could someone please suggest a
workaround to use the code in an R package?
[1]: http://dpaste.com/209186/
More information about the R-help
mailing list