Naira wrote:
Hi all,

I would like to know if it is possible in R to give a the reference of a
variable in a function; in order to be able  to change the variable in the
function and to keep the change when the function ended.
In other words, is it possible to code this following C code in R:
void functionName(int &var){}

No, not directly. There are tricks to achieve the same thing (e.g. put the variable in an environment and pass the environment instead), but generally speaking you are better off using R as if it was a functional language, i.e. avoiding side effects in your functions. Use

x <- modify(x)

rather than expecting modify() to make changes to the things passed to it.

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to