Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.8%) to scientific vocabulary
Last synced: 6 months ago
·
JSON representation
Repository
Parse and Manipulate R Code
Basic Info
- Host: GitHub
- Owner: etiennebacher
- License: other
- Language: R
- Default Branch: main
- Homepage: https://astgrepr.etiennebacher.com/
- Size: 91.9 MB
Statistics
- Stars: 27
- Watchers: 1
- Forks: 2
- Open Issues: 5
- Releases: 11
Created about 2 years ago
· Last pushed 9 months ago
Metadata Files
Readme
Changelog
License
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# astgrepr
[](https://github.com/etiennebacher/astgrepr/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/etiennebacher/astgrepr?branch=main)
[](https://CRAN.R-project.org/package=astgrepr)
`astgrepr` provides R bindings to the [ast-grep](https://ast-grep.github.io/)
Rust crate. `ast-grep` is a tool to parse the abstract syntax tree (AST) of some
code and to perform search and rewrite of code. This is extremely useful to build
linters, stylers, and perform a lot of code analysis.
See the example below and the [“Getting started”
vignette](https://astgrepr.etiennebacher.com/articles/astgrepr) for
a gentle introduction to `astgrepr`.
Since `astgrepr` can be used as a low-level foundation for other tools (such as
linters), the number of R dependencies is kept low:
```r
> pak::local_deps_tree()
✔ Loading metadata database ... done
local::. 0.0.1 [new][bld]
├─checkmate 2.3.1 [new][dl] (746.54 kB)
│ └─backports 1.5.0 [new]
├─rrapply 1.2.7 [new]
└─yaml 2.3.8 [new][dl] (119.08 kB)
Key: [new] new | [dl] download | [bld] build
```
## Installation
``` r
install.packages("astgrepr")
```
Development version (you might need to install [Rust](https://www.rust-lang.org/tools/install)):
```r
# install.packages("remotes")
remotes::install_github("etiennebacher/astgrepr")
```
## Demo
```{r}
library(astgrepr)
src <- "library(tidyverse)
x <- rnorm(100, mean = 2)
any(duplicated(y))
plot(x)
any(duplicated(x))
any(is.na(variable))"
root <- src |>
tree_new() |>
tree_root()
# get everything inside rnorm()
root |>
node_find(ast_rule(pattern = "rnorm($$$A)")) |>
node_get_multiple_matches("A") |>
node_text_all()
# find occurrences of any(duplicated())
root |>
node_find_all(ast_rule(pattern = "any(duplicated($A))")) |>
node_text_all()
# find some nodes and replace them with something else
nodes_to_replace <- root |>
node_find_all(
ast_rule(id = "any_na", pattern = "any(is.na($VAR))"),
ast_rule(id = "any_dup", pattern = "any(duplicated($VAR))")
)
fixes <- nodes_to_replace |>
node_replace_all(
any_na = "anyNA(~~VAR~~)",
any_dup = "anyDuplicated(~~VAR~~) > 0"
)
# original code
cat(src)
# new code
tree_rewrite(root, fixes)
```
## Related tools
There is some recent work linking `tree-sitter` and R. Those are not competing
with `astgrepr` but are rather a complement to it:
* [`r-lib/tree-sitter-r`](https://github.com/r-lib/tree-sitter-r): provide the
R grammar to be used with tools built on `tree-sitter`. `astgrepr` relies on
this grammar under the hood.
* [`DavisVaughan/r-tree-sitter`](https://github.com/DavisVaughan/r-tree-sitter):
a companion of `r-lib/tree-sitter-r`. This gives a way to get the tree-sitter
representation of some code directly in R. This is useful to learn how
tree-sitter represents the R grammar, which is required if you want advanced
use of `astgrepr`. However, it doesn't provide a way to easily select specific
nodes (e.g. based on patterns).
Owner
- Name: Etienne Bacher
- Login: etiennebacher
- Kind: user
- Website: etiennebacher.com
- Repositories: 147
- Profile: https://github.com/etiennebacher
GitHub Events
Total
- Create event: 9
- Release event: 2
- Issues event: 4
- Watch event: 7
- Delete event: 2
- Issue comment event: 18
- Push event: 51
- Pull request event: 17
- Fork event: 4
Last Year
- Create event: 9
- Release event: 2
- Issues event: 4
- Watch event: 7
- Delete event: 2
- Issue comment event: 18
- Push event: 51
- Pull request event: 17
- Fork event: 4
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 22
- Total pull requests: 31
- Average time to close issues: 19 days
- Average time to close pull requests: 7 days
- Total issue authors: 3
- Total pull request authors: 3
- Average comments per issue: 1.27
- Average comments per pull request: 0.65
- Merged pull requests: 24
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 6
- Pull requests: 23
- Average time to close issues: 27 days
- Average time to close pull requests: 3 days
- Issue authors: 2
- Pull request authors: 3
- Average comments per issue: 1.0
- Average comments per pull request: 0.65
- Merged pull requests: 16
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- etiennebacher (23)
- IndrajeetPatil (1)
- Exceret (1)
Pull Request Authors
- etiennebacher (30)
- JosiahParry (5)
- mpadge (2)
Top Labels
Issue Labels
help wanted (1)
false-positive (1)
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 362 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 2
- Total maintainers: 1
cran.r-project.org: astgrepr
Parse and Manipulate R Code
- Homepage: https://github.com/etiennebacher/astgrepr
- Documentation: http://cran.r-project.org/web/packages/astgrepr/astgrepr.pdf
- License: MIT + file LICENSE
-
Latest release: 0.1.1
published 9 months ago
Rankings
Dependent packages count: 26.4%
Dependent repos count: 32.5%
Average: 48.5%
Downloads: 86.6%
Maintainers (1)
Last synced:
7 months ago
Dependencies
.github/workflows/R-CMD-check.yaml
actions
- actions/checkout v4 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml
actions
- JamesIves/github-pages-deploy-action v4.5.0 composite
- actions/checkout v4 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
src/rust/Cargo.lock
cargo
- 114 dependencies
src/rust/Cargo.toml
cargo
DESCRIPTION
cran
- checkmate * imports
- rrapply * imports
- stringi * imports
- utils * imports
- yaml * imports
- knitr * suggests
- rmarkdown * suggests
- rstudioapi * suggests
- tinytest * suggests