Traitement de données évolutif en R
Simon Urbanek
Member of R-Core, Lead Inventive Scientist, AT&T Labs Research
big.matrix est stockée sur le disqueCeci crée une copie de a et l'affecte à b.
a <- 42
b <- a
a
42
b
42
a <- 43
a
43
b
42
a <- 42foo <- function(a){a <- 43 paste("Inside the function a is", a)}
foo(a)
"À l'intérieur de la fonction, a vaut 43"
paste("Outside the function a is still", a)
"À l'extérieur de la fonction, a vaut encore 42"
Cette fonction modifie bien la valeur de a dans l'environnement global
foo <- function(a) {a$val <- 43
paste("Inside the function a is", a$val)}
a <- environment()
a$val <- 42
foo(a)
"À l'intérieur de la fonction, a vaut 43"
paste("Outside the function a$val is", a$val)
"À l'extérieur de la fonction, a$val vaut 43"
# x est une grande matrice
x <- big.matrix(...)
# x_no_copy et x renvoient au même objet
x_no_copy <- x
# x_copy et x renvoient à des objets différents
x_copy <- deepcopy(x)
R ne fera pas de copies implicitement
library(bigmemory)
x <- big.matrix(nrow = 1, ncol = 3, type = "double",
init = 0,
backingfile = "hello-bigmemory.bin",
descriptorfile = "hello-bigmemory.desc")
x_no_copy <- x
x[,]
0 0 0
x_no_copy[,]
0 0 0
x[,] <- 1
x[,]
1 1 1
x_no_copy[,]
1 1 1
x_copy <- deepcopy(x)
x[,]
1 1 1
x_copy[,]
1 1 1
x[,] <- 2
x[,]
2 2 2
x_copy[,]
1 1 1
Traitement de données évolutif en R