| name | lobstr |
| description | R lobstr package for memory inspection. Use for understanding R object memory usage and structure. |
lobstr
Visualize R data structures.
Object Size
library(lobstr)
obj_size(x)
obj_size(x, y)
obj_size(x, y)
Object Address
obj_addr(x)
obj_addr(x) == obj_addr(y)
Reference Counting
ref(x)
x <- 1:10
y <- x
ref(x)
AST (Abstract Syntax Tree)
ast(f(x, y))
ast(
if (x > 0) {
sqrt(x)
} else {
-sqrt(-x)
}
)
Object Tree
sxp(x)
sxp(list(a = 1, b = 2))
Memory Tracking
x <- 1:1e6
obj_size(x)
y <- x
obj_size(x, y)
y[1] <- 0L
obj_size(x, y)
Compare Sizes
sizes <- c(
"vector" = obj_size(1:1000),
"list" = obj_size(as.list(1:1000)),
"df" = obj_size(data.frame(x = 1:1000))
)
sizes
Memory Efficiency
obj_size(1:1000)
obj_size(as.double(1:1000))
x <- rep("hello", 1000)
obj_size(x)
Tree Visualization
tree(quote(f(g(x), h(y, z))))