Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/r-lib/lobstr

Understanding complex R objects with tools similar to str()
https://github.com/r-lib/lobstr

r

Last synced: 6 days ago
JSON representation

Understanding complex R objects with tools similar to str()

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(lobstr)
```

# lobstr lobstr website

[![CRAN status](https://www.r-pkg.org/badges/version/lobstr)](https://cran.r-project.org/package=lobstr)
[![R-CMD-check](https://github.com/r-lib/lobstr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/lobstr/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-lib/lobstr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/lobstr?branch=main)

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())
```