Search notes:

R function: environment

Passing by reference

With environments, is possible to create a very crude pass by reference mechanism:
fnc <- function(x) x$val <- x$val * x$val;

lst <- list(val = 3);
fnc(lst);
lst$val;
#
# 3

env <- new.env();
env$val <- 3;
fnc(env);
env$val;
#
# 9
Github repository about-R, path: /environment/pass-by-reference.R

See also

new.env, environment, globalenv
Functions in R
body, formals
Index to (some) R functions

Index