https://github.com/sckott/astr
https://github.com/sckott/astr
ast package r rstats
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sckott/astr
- Owner: sckott
- License: other
- Created: 2020-05-06T21:43:53.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-10T04:54:55.000Z (over 1 year ago)
- Last Synced: 2026-01-11T11:32:41.721Z (6 months ago)
- Topics: ast, package, r, rstats
- Language: R
- Homepage: https://sckott.github.io/astr/
- Size: 1.02 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
astr
====
```{r echo=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
collapse = TRUE,
comment = "#>"
)
```
[](https://github.com/sckott/astr/actions/)
[](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