Empty R environment becomes large file when saved

Posted by user1052019 on Stack Overflow See other posts from Stack Overflow or by user1052019
Published on 2012-12-17T11:02:17Z Indexed on 2012/12/17 11:02 UTC
Read the original article Hit count: 133

Filed under:

I'm getting behaviour I don't understand when saving environments.

The code below demonstrates the problem. I would have expected the two files (far-too-big.RData, and right-size.RData) to be the same size, and also very small because the environments they contain are empty.

In fact, far-too-big.R ends up the same size as bigfile.RData.

I get the same results using 2.14.1 and 2.15.2, both on WinXP 5.1 SP3.

Can anyone explain why this is happening?

Thanks.

a <- matrix(runif(1000000, 0, 1), ncol=1000)
save(a, file="c:/temp/bigfile.RData")


test <- function() {

    load("c:/temp/bigfile.RData")

    test <- new.env()
    save(test, file="c:/temp/far-too-big.RData")

    test1 <- new.env(parent=globalenv())
    save(test1, file="c:/temp/right-size.RData")

}

test()

© Stack Overflow or respective owner

Related posts about r