Skip to contents

The primary user-facing function. Orchestrates project detection, AST parsing, edge construction, TF-IDF (or alternative) embedding, and igraph assembly into a typed knowledge graph.

Usage

build_rrlm_graph(
  project_path = ".",
  embed_method = "tfidf",
  include_package_nodes = TRUE,
  semantic_threshold = 0.7,
  max_semantic_edges = 5L,
  cache = TRUE,
  verbose = FALSE
)

Arguments

project_path

Character(1). Path to the R project root. Defaults to ".".

embed_method

Character(1). Embedding back-end: "tfidf" (default), "ollama", or "openai". Only "tfidf" is available in Sprint 1.

include_package_nodes

Logical(1). When TRUE (default), one node per unique external package is added to the graph.

semantic_threshold

Numeric(1). Minimum cosine similarity for a SEMANTIC edge to be created. Default 0.7.

max_semantic_edges

Integer(1). Maximum SEMANTIC edges to create per node. Capping at a small number (default 5L) prevents dense graphs on large projects. Semantic edges are disabled entirely when the graph has more than 300 function nodes.

cache

Logical(1). When TRUE (default), the graph is serialised to <project_root>/.rrlmgraph/graph.rds.

verbose

Logical(1). When TRUE, progress messages are printed via cli::cli_inform(). Default FALSE.

Value

An object of class c("rrlm_graph", "igraph").

Details

The returned object inherits from igraph and carries the class "rrlm_graph". Graph-level metadata is stored as igraph graph attributes (accessible with igraph::graph_attr()).

Node types

TypeDescription
"function"User-defined R function
"package"External package dependency
"testfile"Test file that references user functions

Edge types

TypeDescription
"CALLS"Intra-project function call
"IMPORTS"File/project imports a package
"TESTS"Test file covers a user function
"SEMANTIC"Cosine similarity >= semantic_threshold
"CO_CHANGES"Two functions co-edited in >= min_cochanges commits (from build_co_change_edges())
"DISPATCHES_ON"S4/R5 generic dispatches on a class (from build_dispatch_edges())
"EXTENDS"Class inherits from another class (from build_dispatch_edges())

Examples

if (FALSE) { # \dontrun{
g <- build_rrlm_graph("/path/to/mypkg")
summary(g)
plot(g)
} # }