-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathREADME.Rmd
86 lines (62 loc) · 1.85 KB
/
README.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(lobstr)
```
# lobstr <a href="https://lobstr.r-lib.org"><img src="man/figures/logo.png" align="right" height="138" alt="lobstr website" /></a>
<!-- badges: start -->
[](https://cran.r-project.org/package=lobstr)
[](https://github.com/r-lib/lobstr/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/r-lib/lobstr?branch=main)
<!-- badges: end -->
lobstr provides tools in the same vein as `str()`, which allow you to dig into the detail of an object.
## Installation
Install the released version of lobstr from CRAN:
``` r
install.packages("lobstr")
```
You can install the development version with:
``` r
# install.packages("pak")
pak::pak("r-lib/lobstr")
```
## Example
### Abstract syntax trees
`ast()` draws the abstract syntax tree of R expressions:
```{r example}
ast(a + b + c)
ast(function(x = 1) {
if (x > 0) print("Hi!")
})
```
### References
`ref()` shows hows objects can be shared across data structures by digging into the underlying __ref__erences:
```{r}
x <- 1:1e6
y <- list(x, x, x)
ref(y)
e <- rlang::env()
e$self <- e
ref(e)
```
A related tool is `obj_size()`, which computes the size of an object taking these shared references into account:
```{r}
obj_size(x)
obj_size(y)
```
### Call stack trees
`cst()` shows how frames on the call stack are connected:
```{r}
f <- function(x) g(x)
g <- function(x) h(x)
h <- function(x) x
f(cst())
```