获取环境在R中使用的RAM量

时间:2014-10-25 22:44:50

标签: r ram

显然object.size在这里不起作用:

> e = new.env()
> e$a = 1:10000
> e$b = 1:10000
> object.size(e)
56 bytes
> e$c = 1:10000
> object.size(e)
56 bytes

2 个答案:

答案 0 :(得分:1)

使用pryr包中的object_size功能:

> library(pryr)
> e = new.env()
> e$a = 1:10000
> e$b = 1:10000
> object.size(e)
28 bytes
> object_size(e)
80.3 kB
> e$c = 1:10000
> object.size(e)
28 bytes
> object_size(e)
120 kB

另见Hadley关于R中记忆的文档:http://adv-r.had.co.nz/memory.html

答案 1 :(得分:0)

一个简单的基础R解决方案:

sum(sapply(e, object.size))