qed
qed

Reputation: 23134

Get the amount of RAM that an environment uses in R

Apparently object.size does not work here:

> 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

Upvotes: 1

Views: 465

Answers (2)

Hong Ooi
Hong Ooi

Reputation: 57696

A simple base R solution:

sum(sapply(e, object.size))

Upvotes: 1

Marek
Marek

Reputation: 50744

Use object_size function from pryr package:

> 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

See also Hadley's doc about memory in R: http://adv-r.had.co.nz/memory.html

Upvotes: 1

Related Questions