# R Support in Maguyva: Code Graphs for Analysis and Package Code

Canonical source: https://maguyva.ai/languages/r

License: text under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/); code samples under [MIT-0](https://opensource.org/license/mit-0); the Maguyva name, logos, brand assets and other code are not covered. Details: [maguyva.ai/license](https://maguyva.ai/license).

Maguyva parses R with AST, symbol, and graph support, so AI agents can follow functions, S3 and S4 dispatch, and model-fitting calls across R scripts and packages.

## Support snapshot

- Tier: AST and symbol support
- Programming
- Extensions: .r, .rmd, .rnw
- Real AST parsing for syntax-aware search and structural context.
- Named symbols feed semantic lookup and cross-reference. Graph navigation is available when relationship extraction is enabled.
- This language contributes symbols and relationships to graph-aware search; supported edge types vary with its native constructs.
- AST parsing and symbol extraction are both available.

## Best fit

- R packages with many exported functions, S3 methods, and internal helpers.
- Analysis pipelines split across scripts that share data-cleaning and modelling functions.
- Data teams handing R code to AI agents that need to see which functions feed which models.

## Agent workflows

- Find every caller of a data-cleaning function before changing the columns it returns.
- Trace which functions dispatch through `UseMethod` and where their methods live.
- Map the path from raw data loading to a fitted model.

## Where R trips up shallow AI tools

R puts base functions, package functions, and your own in one flat namespace. Dots are part of names, not member access: `is.na`, `data.frame`, and `print.summary_table` are single identifiers. A tool that reads `print.summary_table` as a method on `print` gets the structure wrong, and one that records every base call buries your functions under `c()` and `paste()`.

Maguyva keeps R names whole and filters the base noise, so an agent sees the functions your analysis actually depends on.

## What Maguyva extracts in R

Maguyva maps `.R`, `.Rmd`, and `.Rnw` files to R. Functions assigned to a name, such as `clean_survey <- function(df)`, are extracted under that name, and anonymous functions are not treated as definitions. Dotted names are never split into a receiver and a member.

Some base R calls stay in the graph on purpose because they show how analysis code is wired: S3 and S4 dispatch (`UseMethod`, `standardGeneric`), the apply family (`lapply`, `sapply`, `vapply`, `mapply`), model fitting (`lm`, `predict`, `anova`), package loading (`library`, `require`), and error handling with `tryCatch`.

The graph also records instantiation and reads and writes.

## Example agent prompts

- "Who calls `clean_survey`, and which models use its output?" (`find_symbol`, then `dependency_search` incoming)
- "Which functions call `fit_model`?" (`dependency_search`)
- "Trace the path from `load_raw_data` to the final regression." (`get_task_context`)

## Known limits

- About 800 base R, `stats`, and `graphics` names are filtered from relationships, such as `print`, `paste`, `c`, `data.frame`, plotting calls, and random-number generators. Use `text_pattern_search` for them.
- R creates classes and loads packages with ordinary function calls, so the `classes`, `imports`, and `variables` presets in `structural_search` select nothing. Use `find_symbol` and `text_pattern_search`.
- `.Rmd` and `.Rnw` files are read with the R grammar as a whole rather than chunk by chunk, so expect partial results for R Markdown and Sweave documents.
- R has no decorator syntax, so decorator relationships are marked not applicable.

## Next steps

Connect a repository with the [quickstart](/docs/quickstart), then check the support matrix on the [compatibility page](/docs/compatibility). For mixed data-science repos, read the [Python guide](/languages/python) too.

## Engine details

- R support maps `.R`, `.Rmd`, and `.Rnw`. Functions assigned to a name are extracted under that name, and dotted names such as `data.frame` stay whole.
- S3 and S4 dispatch (`UseMethod`, `standardGeneric`), the apply family, `lm`, `predict`, and `tryCatch` are kept in the graph on purpose.
- About 800 base R, `stats`, and `graphics` names, such as `print`, `paste`, and `c`, are filtered from relationships.

## Useful MCP entry points

- `find_symbol`: Use it for a cleaning, modelling, or S3 method name when you need the definition and callers.
- `dependency_search`: Use incoming traversal on a helper function to see which analyses depend on it before changing its output.
- `get_task_context`: Use it for prompts like “trace the path from raw data loading to the final regression.”
