Learn R Programming

funviewR (version 0.1.1)

plot_dependency_graph: Analyze and plot R code dependencies in one step

Description

Convenience function that analyzes R files and directly returns the interactive dependency graph without exposing intermediate analysis results. Automatically detects whether paths are files or directories.

Usage

plot_dependency_graph(
  file_paths,
  include_disconnected = TRUE,
  recursive = FALSE
)

Value

A visNetwork HTML widget displaying the interactive dependency graph. The graph can be saved using htmlwidgets::saveWidget().

Arguments

file_paths

Character vector of R file paths, directory paths, or a mix. The function automatically detects files vs directories.

include_disconnected

Logical. If FALSE, exclude isolated nodes (functions with no dependencies) from the graph. Default is TRUE.

recursive

Logical. If directories are encountered, search subdirectories recursively. Default is FALSE.

Details

This is a convenience wrapper around analyze_internal_dependencies_multi and plot_interactive_dependency_graph. It automatically:

  • Detects whether each path is a file or directory

  • Collects all R files from directories

  • Analyzes function dependencies

  • Creates an interactive visualization

Examples

Run this code
# Create temporary directory and files
temp_dir <- tempfile()
dir.create(temp_dir)

# Create sample R files
writeLines(c(
  "add <- function(a, b) { a + b }",
  "calc <- function(x) { add(x, 10) }"
), file.path(temp_dir, "math.R"))

writeLines(c(
  "process <- function(data) { add(data, 5) }"
), file.path(temp_dir, "process.R"))

# Analyze and plot - single file
graph <- plot_dependency_graph(file.path(temp_dir, "math.R"))

# Analyze directory
graph <- plot_dependency_graph(temp_dir)

# Exclude disconnected nodes
graph <- plot_dependency_graph(temp_dir, include_disconnected = FALSE)

# Clean up
unlink(temp_dir, recursive = TRUE)

Run the code above in your browser using DataLab