R 的可扩展数据处理
Simon Urbanek
Member of R-Core, Lead Inventive Scientist, AT&T Labs Research
big.matrix 存储在磁盘上这会创建 a 的副本并赋给 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)
"Inside the function a is 43"
paste("Outside the function a is still", a)
"Outside the function a is still 42"
此函数会更改全局环境中 a 的值
foo <- function(a) {a$val <- 43
paste("Inside the function a is", a$val)}
a <- environment()
a$val <- 42
foo(a)
"Inside the function a is 43"
paste("Outside the function a$val is", a$val)
"Outside the function a$val is 43"
# x 是一个大矩阵
x <- big.matrix(...)
# x_no_copy 和 x 指向同一对象
x_no_copy <- x
# x_copy 和 x 指向不同对象
x_copy <- deepcopy(x)
R 不会隐式复制
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
R 的可扩展数据处理