Skip to contents

This function analyzes R scripts within two directories: a function directory (e.g., `R` folder for an R package) and an optional code directory (e.g., `inst/scripts` folder). It maps the relationships between functions and scripts, visualizing the connections in a network diagram and providing a data frame of function calls.

Usage

checkPkg_map_functions_and_scripts(function_directory, code_directory = NULL)

Arguments

function_directory

Character. Path to the directory containing R scripts with function definitions (e.g., `R` directory in an R package).

code_directory

Character. Path to the directory containing other R scripts (e.g., `inst/scripts` directory). Default is NULL.

Value

A list with two elements:

vis_plot

An interactive network plot showing the relationships between functions and scripts.

df_to_from

A data frame mapping function-to-function and function-to-script relationships.

Details

The function performs the following steps: 1. Scans the `function_directory` to identify R scripts and extracts all defined functions. 2. Optionally scans the `code_directory` for additional scripts. 3. Maps function calls within and across scripts, creating a data frame of relationships. 4. Visualizes the relationships in an interactive network plot using visNetwork.

The function can be used to understand code dependencies, identify potential redundancies, and visualize how functions and scripts interact within a project.

Note

This function assumes that R scripts in the `function_directory` contain properly defined functions, and that scripts in the `code_directory` may invoke these functions.

Examples

if (FALSE) { # \dontrun{
checkPkg_map_functions_and_scripts(function_directory = "R", code_directory = "inst/scripts")
} # }