Add: R (.r/.R) language support via bespoke extract_r#1933
Open
Sirhan1 wants to merge 1 commit into
Open
Conversation
Adds a new bespoke R extractor under graphify/extractors/, following the Julia/Elixir precedent. Handles the five function-assignment forms (<-, <<-, =, ->, ->>), nested function scoping, top-level vs function-level call attribution, member ($/@) and package-qualified (::/:::) raw_calls, pipes (|>/%>%), static library/require/requireNamespace imports, and static source() cross-file linkage. Unqualified bare calls route through the shared raw_calls resolver with an R language-family guard that blocks binding to non-R definitions. Wires .r into _DISPATCH/_EXTRA_FOR_EXTENSION/_LANG_FAMILY_BY_EXT and Rscript into _SHEBANG_DISPATCH; .R reuses the existing case-insensitive suffix fallback. Ships under optional [r] extra via tree-sitter-language-pack (no maintained tree-sitter-r wheel fits the per-language model); the pack may fetch/cache the R grammar on first use (no source uploaded, R not executed). Fixes Graphify-Labs#1689 for .R (no longer a no-AST-extractor case) and reuses the existing Graphify-Labs#1745 install-extra warning with pip install "graphifyy[r]". Adds tests/fixtures/sample.r + 3 cross-file fixtures, 22 R tests in test_languages.py following the DM optional-grammar skip-when-unavailable convention, and 2 dispatch/missing-dep tests in test_extract.py. R package metadata (DESCRIPTION/NAMESPACE/exports) and package-qualified call resolution are deferred to a follow-up (Graphify-Labs#9).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds initial support for R (
.r/.R) source files via a dedicatedextract_rextractor, following the same approach used for Julia and Elixir.The scope is intentionally limited to R source code structure and call relationships. Package metadata (
DESCRIPTION,NAMESPACE, exports), package-qualified resolution,.Rmdsupport, and other R-specific semantics are intentionally deferred to a follow-up PR.Why a dedicated extractor?
Unlike languages with named function declarations, R functions are typically anonymous functions assigned to variables:
Tree-sitter represents these as assignments containing anonymous function definitions rather than named declarations, making the generic extractor a poor fit. This follows the existing pattern used for other languages that require bespoke extractors.
What this PR adds
Parser integration
rextra usingtree-sitter-language-pack.r,.R, andRscriptpip install "graphifyy[r]")R extraction
The new extractor supports:
<-<<-=->->>pkg::fn,pkg:::fn)$,@)|>,%>%)Nested function bodies are skipped while traversing an enclosing function to prevent double attribution.
Imports
Supports static detection of:
library()require()requireNamespace()source("file.R")source()imports are only created when the referenced file exists locally, matching Graphify's existing behaviour for Bashsource.Tests
Added:
The optional grammar follows the same testing pattern as the existing optional language parsers:
The implementation was also verified on a synthetic multi-file R project covering common R idioms, including nested functions, pipes, package-qualified calls, cross-file resolution, and ambiguous definitions.
Results
ruff checkpyrightgraphify update .Out of scope
The following are intentionally deferred to a future PR:
DESCRIPTION/NAMESPACEparsing.Rmdextractionrenv.lockintegration