-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathObjectSize.Rmd
57 lines (47 loc) · 1.33 KB
/
ObjectSize.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "Object Size"
author: "John Mount, Win-Vector LLC"
date: "3/17/2017"
output:
md_document:
variant: markdown_github
---
Many of the object size estimation methods in `R` have different opinions as to whether they count environments, which can be a very large component of objects.
Some related articles:
* [Trimming the Fat from glm Models in R](http://www.win-vector.com/blog/2014/05/trimming-the-fat-from-glm-models-in-r/)
* [How and why to return functions in R](http://www.win-vector.com/blog/2015/04/how-and-why-to-return-functions-in-r/)
```{r}
build1 <- function() {
x <- 1:1e+7 # this variable will be in f's closure
f = function(i) {
print(x[[i]])
}
print(paste(
"serialize size in construction environment",
length(serialize(f, NULL))
))
print(paste(
"pryr::object_size in construction environment",
pryr::object_size(f)
))
print(paste(
"utils::object.size in construction environment",
utils::object.size(f)
))
f
}
f <- build1()
print(paste(
"serialize size in global environment",
length(serialize(f, NULL))
))
print(paste(
"pryr::object_size in global environment",
pryr::object_size(f)
))
print(paste(
"utils::object.size in global environment",
utils::object.size(f)
))
```
(Filed as [pryr issue 37](https://github.com/hadley/pryr/issues/37), and closed.)