fn_graph: Render a function call graph for an R project

View source: R/fn_graph.R

fn_graphR Documentation

Render a function call graph for an R project

Description

Pulls the AST symbol index via symbols and renders internal function-to-function call edges as SVG. External calls (into other packages) are dropped by default.

Usage

fn_graph(
  project_dir,
  include_external = FALSE,
  ...,
  cache_dir = file.path(tools::R_user_dir("saber", "cache"), "symbols")
)

Arguments

project_dir

Path to the project directory (an R package root).

include_external

If TRUE, also include nodes for functions called from other packages. Default FALSE.

...

Passed through to graph_svg (e.g., width, height, iterations, seed).

cache_dir

Directory for the underlying symbols cache. Pass tempdir() (or any non-default path) when running examples / tests to avoid writing to the user's persistent cache. Name-only argument; pass it by name.

Value

Character vector of SVG lines. Write with writeLines().

Examples

d <- file.path(tempdir(), "fngdemo")
dir.create(file.path(d, "R"), recursive = TRUE, showWarnings = FALSE)
writeLines(c("Package: demo", "Version: 0.1.0"),
           file.path(d, "DESCRIPTION"))
writeLines("add <- function(x, y) x + y", file.path(d, "R", "add.R"))
writeLines("double <- function(x) add(x, x)",
           file.path(d, "R", "double.R"))
svg <- fn_graph(d, cache_dir = tempdir())
writeLines(svg, tempfile(fileext = ".svg"))

saber documentation built on Nov. 10, 2026, 9:06 a.m.