Learn R Programming

funviewR (version 0.1.1)

analyze_internal_dependencies_multi: Analyze internal dependencies in R source files

Description

Parses multiple R files to identify function definitions and their internal dependencies. Creates a comprehensive map of which functions call which other functions within the analyzed codebase.

Usage

analyze_internal_dependencies_multi(file_paths)

Value

A list with the following components:

dependency_map

Named list mapping function names to character vectors of their dependencies

env

Environment containing all parsed functions

all_code_lines

Character vector of all code lines from all files

function_file_map

Named list mapping function names to their source file paths

duplicates

List of functions defined in multiple files with their source locations

Arguments

file_paths

Character vector of R file paths to analyze.

Details

This function uses codetools::findGlobals() to detect function calls within function bodies. Only functions defined within the analyzed files are tracked. External package functions and base R functions are not included in the dependency map.

Examples

Run this code
# Create temporary R files for demonstration
temp_file1 <- tempfile(fileext = ".R")
temp_file2 <- tempfile(fileext = ".R")

# Write sample R code to temporary files
writeLines(c(
  "add_numbers <- function(a, b) {",
  "  a + b",
  "}",
  "",
  "calculate_sum <- function(x) {",
  "  add_numbers(x, 10)",
  "}"
), temp_file1)

writeLines(c(
  "multiply <- function(a, b) {",
  "  a * b",
  "}",
  "",
  "process_data <- function(x) {",
  "  result <- add_numbers(x, 5)",
  "  multiply(result, 2)",
  "}"
), temp_file2)

# Analyze the files
dep_info <- analyze_internal_dependencies_multi(c(temp_file1, temp_file2))

# View the dependency map
print(dep_info$dependency_map)

# Check for duplicate function definitions
if (length(dep_info$duplicates) > 0) {
  message("Warning: Functions defined in multiple files:")
  print(dep_info$duplicates)
}

# Clean up
unlink(c(temp_file1, temp_file2))

Run the code above in your browser using DataLab