Title: | Map User-Created Functions |
Version: | 1.0.0 |
Description: | Create an interactive function map by analyzing a specified R script. It uses the find_dependencies() function from the 'functiondepends' package to recursively trace all user-defined function dependencies. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Imports: | magrittr, functiondepends, glue, visNetwork, htmlwidgets |
Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-07-19 16:12:22 UTC; root |
Author: | Antonio Fratamico [aut, cre] |
Maintainer: | Antonio Fratamico <fratamicoa@outlook.com> |
Repository: | CRAN |
Date/Publication: | 2025-07-22 10:10:02 UTC |
Brief: Build Recursive Dependency Map of User-Defined Functions
Description
Description: This function recursively builds a list of data frames, each representing a user-defined function and its dependencies. Starting from the main function (typically the main script wrapped as a function), it uses find_dependencies() from the functiondepends package to trace all user-defined function calls. The process continues until no new dependencies are found.
Usage
build_dependency_map(
func_name,
visited = character(),
all_deps = list(),
env = parent.frame()
)
Arguments
func_name |
The name of the main function (converted from the main script) to begin tracing dependencies from. |
visited |
A character vector used to track already visited functions and prevent infinite recursion. |
all_deps |
A list used to accumulate the dependency data frames for each user-defined function. |
env |
The local enviroment created in funcMapper() |
Details
Author: Antonio Fratamico Date: 10/07/2025
Value
A named list of data frames, where each data frame contains the dependencies of a user-defined function.
Brief: Map User Created Functions in any R Script
Description
Description: This function generates an interactive function map of all user-defined functions that originate from a specified R script (the "main script"). It leverages the find_dependencies() function from the functiondepends package to recursively trace all user-created function dependencies within the script.
Usage
funcMapper(
script_path,
output_name,
output_path,
source = FALSE,
cleanup_temp_file = TRUE
)
Arguments
script_path |
File path of R script you wish to map the functions of (need to specify .R at end of script name) |
output_name |
name of the function map (no need to specify .html) |
output_path |
path to save function map to (no need for '/' at end of path) |
source |
run the script if have not done already to load functions into environment (default is FALSE not to run it) |
cleanup_temp_file |
delete temporary script file converted into function for the mapping process (default is TRUE - might not want to delete) |
Details
The process begins by converting the main script into a function (if it isn't already), enabling the tool to identify and highlight the root function in the resulting map. It then iteratively explores each function, parsing and mapping any nested user-defined functions until the full dependency tree is uncovered.
The final output is a hierarchical VisNetwork visualisation that clearly illustrates the structure and relationships between functions, with the main script node distinctly highlighted in red for easy identification.
Author: Antonio Fratamico Date: 10/07/2025
Value
Save a function map (html file) in designated output path
Brief: Convert Dependency Map to Edge List
Description
Description: Converts a dependency map (as produced by build_dependency_map(), which is a list of data frames representing function dependencies, into a unified edge list with from and to columns. This format is required for visualizing the function relationships using visNetwork.
Usage
get_edges_from_map(dep_map)
Arguments
dep_map |
A named list of data frames, where each data frame contains the dependencies of a user-defined function. |
Details
Author: Antonio Fratamico Date: 10/07/2025
Value
A data frame representing the edge list, with columns from and to, suitable for plotting with visNetwork.
Brief: Plot dependencies map from dep_map and save HTML file
Description
Description: This function plots the dep_map from build_dependency_map(), by first passing it through get_edges_from_map() to convert it from a list of data frames to a unified edge list, which is then used in a visNetwork plot. This is then saved to the output path with the output name (both defined in funcMapper) as an HTML file.
Usage
plot_dependency_graph(
dep_map,
output_path,
output_name,
main_node = script_name
)
Arguments
dep_map |
A named list of data frames, where each data frame contains the dependencies of a user-defined function. |
output_path |
path to save function map to (defined in funcMapper) |
output_name |
name of the function map (defined in funcMapper) |
main_node |
this is always set to the script name, generated from script path in funcMapper. Used to highlight main script node in red. |
Details
Author: Antonio Fratamico Date: 10/07/2025
Value
A visNetwork plot of the user created function map, saved to the output path