显然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
答案 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))