Skip to content

Instantly share code, notes, and snippets.

@slwu89
Created November 5, 2021 21:54
Show Gist options
  • Save slwu89/a294203e6d6679b923276030516684d7 to your computer and use it in GitHub Desktop.
Save slwu89/a294203e6d6679b923276030516684d7 to your computer and use it in GitHub Desktop.
when do things get copied in R?
fn_list <- function(y){
y$a <- y$a + 1
return(y)
}
fn_env <- function(y){
y$a <- y$a + 1
}
x <- list(a=matrix(1:9,3,3),b=matrix(1:36,6,6))
.Internal(inspect(x))
x <- fn_list(x)
.Internal(inspect(x))
y <- list2env(list(a=matrix(1:9,3,3),b=matrix(1:36,6,6)))
.Internal(inspect(y))
fn_env(y)
.Internal(inspect(y))
stopifnot(x$a == y$a)
stopifnot(x$b == y$b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment