Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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()
- Host: GitHub
- URL: https://github.com/r-lib/lobstr
- Owner: r-lib
- License: other
- Created: 2015-03-20T20:57:44.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2023-10-30T18:52:51.000Z (about 1 year ago)
- Last Synced: 2025-01-16T16:25:46.644Z (9 days ago)
- Topics: r
- Language: R
- Homepage: https://lobstr.r-lib.org/
- Size: 1.55 MB
- Stars: 304
- Watchers: 13
- Forks: 28
- Open Issues: 14
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- jimsghstars - r-lib/lobstr - Understanding complex R objects with tools similar to str() (R)
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)
```[![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())
```