R has pass-by-reference (sort of). When you assign an object to another variable or pass to a function, another reference is created. However, if you modify the object through one of the references, that's when an actual copy is made.
f <- function(m) {
.Internal(inspect(m))
}
g <- function(m) {
m[1] <- 0
.Internal(inspect(m))
}
m <- matrix(1,1)
.Internal(inspect(m))
## @452e308 14 REALSXP g0c1 [NAM(2),ATT] (len=1, tl=0) 1
## ATTRIB:
## @42c8ee8 02 LISTSXP g0c0 []
## TAG: @2faaf98 01 SYMSXP g0c0 [MARK,LCK,gp=0x4000] "dim" (has value)
## @452e2d8 13 INTSXP g0c1 [NAM(2)] (len=2, tl=0) 1,1
# f shows that this is the same object (@452e308):
f(m)
## @452e308 14 REALSXP g0c1 [NAM(2),ATT] (len=1, tl=0) 1
## ATTRIB:
## @42c8ee8 02 LISTSXP g0c0 []
## TAG: @2faaf98 01 SYMSXP g0c0 [MARK,LCK,gp=0x4000] "dim" (has value)
## @452e2d8 13 INTSXP g0c1 [NAM(2)] (len=2, tl=0) 1,1
# g shows a newly allocated object (@3941998):
g(m)
## @3941998 14 REALSXP g0c1 [NAM(1),ATT] (len=1, tl=0) 0
## ATTRIB:
## @3b9fc80 02 LISTSXP g0c0 []
## TAG: @2faaf98 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "dim" (has value)
## @3941ae8 13 INTSXP g0c1 [NAM(2)] (len=2, tl=0) 1,1