--- title: "function tree" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{function tree} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- This vignette demonstrates how to explore **function call relationships** inside an R package (using `pkgnet`). - The call graph is directed **caller → callee**. - **Downstream** means *who this function calls*; - **Upstream** means *who calls this function*. ## function_tree ```{r} library(risk.assessr) library(whatsnew) ft <- whatsnew::function_tree("risk.assessr") ft ``` ```{r} ft1 <- whatsnew::function_tree("risk.assessr", root = "assess_pkg_r_package", depth = 3, direction = "downstream") str(ft1, max.level = 3) ``` ```{r} ft2 <- whatsnew::function_tree("risk.assessr", root = "assess_pkg_r_package", depth = 3, direction = "upstream") str(ft2, max.level = 3) ``` ## function_tree print ```{r} whatsnew::print_function_tree(ft) ``` ## function_tree with exported function ```{r} here_version <- "1.0.1" # Version of `here` used to generate test archive temp_file <- tryCatch(system.file("test-data", "here_101.tar.gz", package = "whatsnew")) temp_dir <- tempfile() dir.create(temp_dir) untar(temp_file, exdir = temp_dir) pkg_source_path <- list.dirs(temp_dir, full.names = TRUE, recursive = FALSE)[1] exports_df <- risk.assessr::get_exports(pkg_source_path) ``` ```{r} exports_df$exported_function ``` ```{r} if (requireNamespace("here", quietly = TRUE)) { # pkgnet analyses the installed package; its namespace must be attached. library(here) res <- function_tree("here") print_function_tree(res) res <- function_tree("here", prune = exports_df$exported_function) print_function_tree(res) } ```