Skip to content
Prev 303315 / 398506 Next

pass by reference

You can use macros for this effect. Or environments:

daf <- data.frame(a=1:10, b=rnorm(10))
env <- as.environment(daf)

fun <- function(x) x$c <- x$a+x$b
fun(daf)
fun(env)

daf$c
env$c

You can see that the same function (fun) changes one object but leaves
another one unchanged. But before using it for something important,
think of the side effects and efficiency. Passing by value does not
create as many unnecessary copies as one might think.

On Tue, Aug 14, 2012 at 4:08 AM, Sachinthaka Abeywardana
<sachin.abeywardana at gmail.com> wrote: