A Better R Programming Experience Thanks to Tree-sitter
Key point
Tree-sitter has greatly improved editing, search, and linting in the R ecosystem.
Details
Tree-sitter parses code syntax quickly, and in particular with incremental parsing, it instantly updates the syntax tree in editors even while typing. This approach has also been applied to R, greatly improving the development experience.
Parsing R's syntax allows identifying tokens like LEFT_ASSIGN and SYMBOL_FUNCTION_CALL, which enable code analysis, navigation, and modification without regular expressions. Tree-sitter handles this work faster and more generically, providing a grammar-based structure that can be commonly applied across multiple languages.
The core foundation is the Tree-sitter grammar for R created by Davis Vaughan and others. Thanks to this grammar, tools for R are being connected one by one.
- On GitHub, function definitions are better surfaced in R code search results.
- The Ark R kernel in the Positron IDE provides autocomplete and hover help.
- Tree-sitter support can also be leveraged in other editors like Emacs.
The ecosystem tools are also laid out in detail.
- The {treesitter} R package performs parsing and query searches on R code.
- {gander} provides a better experience when working with R code alongside LLMs.
- {igraph.r2cdocs} parses R source to automatically find documentation linked to
_implfunctions. - {pkgdepends} uses Tree-sitter to detect dependencies within files.
- ast-grep and {astgrepr} enable structural search and refactoring.
Rust-based CLIs are also strongly highlighted for their editing speed and ease of installation.
- Air is a Tree-sitter-based formatter.
- Jarl is a Tree-sitter-based linter and auto-fix tool.
- CLIs are easy to integrate into IDEs, and are simpler to install in CI than R packages.
Finally, beyond R, Tree-sitter is expanding into areas such as TOML/JSON editing, mutation testing, and structural diffing. Overall, this article shows how Tree-sitter has substantively elevated the R developer experience, and what tool ecosystem has been built on top of it.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.