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

https://github.com/sckott/astr


https://github.com/sckott/astr

ast package r rstats

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

astr
====

```{r echo=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
collapse = TRUE,
comment = "#>"
)
```

[![R-check](https://github.com/sckott/astr/workflows/R-check/badge.svg)](https://github.com/sckott/astr/actions/)
[![codecov.io](https://codecov.io/github/sckott/astr/coverage.svg?branch=mastr)](https://codecov.io/github/sckott/astr?branch=mastr)

Decompose and Recompose Functions

## Install

```{r eval=FALSE}
remotes::install_github("sckott/astr")
```

```{r}
library("astr")
```

## decompose

a simple function

```{r}
foo <- function(x) {
x + 1
}
foo(5)
```

decompose the function

```{r}
df <- ast_decompose(foo)
df
class(df)
```

## modify

modify an aspect of the function

```{r}
out <- ast_modify(df, from = "+", to = "-")
out
```

## recompose

```{r}
ast_recompose(out)
ex <- ast_recompose(out, as_expr = TRUE)
eval(ex)(5)
```

## Meta

* Please [report any issues or bugs](https://github.com/sckott/astr/issues).
* License: MIT
* Get citation information for `astr` in R doing `citation(package = 'astr')`
* Please note that this project is released with a [Contributor Code of Conduct][coc]. By participating in this project you agree to abide by its terms.

[coc]: https://github.com/sckott/astr/blob/mastr/CODE_OF_CONDUCT.md