Hi ran the following lines and was a bit surprised. Confusion inline:
Ok so I create a list:
> x<-list()
assign 1 to be an element indexed by "a"
> x$a<-1
I ask to see what is in x
> x
$a
[1] 1
yup so far so good
next I declare a function that will take list that is passed to it and like the assignment to index "a" I'll just assign to index "b" value 2
> foo<-function(xx) {
+ xx["b"]<-2
+ print(xx)
+ }
I call the function with x - I like what I see Now my thinking is that the list object got passed (by reference as in C when you do &x) and it was destructively modified
> foo(x)
$a
[1] 1
$b
[1] 2
Now outside the body of the function I print x -- but surprised not to see b
> x
$a
[1] 1
>
I read scooping and parameter passing docs but couldn't figure this out. Is the list being deep or shallow copied before the function body is invoked?