You can install it by running:
Visualising R data structures with trees
Abstract syntax trees
ast(a + b + c) #> █─`+` #> ├─█─`+` #> │ ├─a #> │ └─b #> └─c
Call stack trees
cst() shows how the frames of a call stack are connected:
f <- function(x) g(x) g <- function(x) h(x) h <- function(x) x f(cst()) #> █ #> 1. ├─global::f(cst()) #> 2. │ └─global::g(x) #> 3. │ └─global::h(x) #> 4. └─lobstr::cst()
Learn more about this in The call stack.
x <- 1:100 ref(x) #> [1:0x7fb19c66bbc8] <int> y <- list(x, x, x) ref(y) #> █ [1:0x7fb19d0d5a28] <list> #> ├─[2:0x7fb19c66bbc8] <int> #> ├─[2:0x7fb19c66bbc8] #> └─[2:0x7fb19c66bbc8]
obj_addr() function gives the address of the value that an object,
x, points to. In Binding basics, this is used to illustrate the “lazy copying” used by R: when multiple names reference the same value, they point to the same identifier. The object itself is not duplicated.
x <- 1:10 y <- x obj_addr(x) #>  "0x7fb19c7aeeb0" obj_addr(y) #>  "0x7fb19c7aeeb0"
obj_size() computes the size of an object or set of objects. It is different to
object.size() in three ways. It:
- Accounts for all types of shared values, not just strings in the global string pool,
- Includes the size of environments (up to
- Accurately measures the size of ALTREP objects.
obj_size() attempts to take into account the size of the environments associated with an object. By default, it never counts the size of the global environment, the base environment, the empty environment, or any namespace. However, the optional
env argument allows you to specify another environment at which to stop.
x <- runif(1e4) obj_size(x) #> 80,048 B z <- list(a = x, b = x, c = x) obj_size(z) #> 80,488 B
You can use
obj_sizes() to see the unique contribution of each component:
obj_sizes(x, z) #> * 80,048 B #> * 440 B
For more detail, see the Object size section of Advanced R.