diff --git a/README.Rmd b/README.Rmd index 4273b7f..a1d8f2d 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,6 +1,5 @@ --- output: github_document -always_allow_html: true --- @@ -18,7 +17,6 @@ knitr::opts_chunk$set( # foodwebr -[![R-CMD-check](https://github.com/lewinfox/foodwebr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/lewinfox/foodwebr/actions/workflows/R-CMD-check.yaml) `foodwebr` makes it easy to visualise the dependency graph of a set of functions (i.e. who calls @@ -42,15 +40,8 @@ library(foodwebr) f <- function() 1 g <- function() f() -h <- function() { - f() - g() -} -i <- function() { - f() - g() - h() -} +h <- function() { f(); g() } +i <- function() { f(); g(); h() } j <- function() j() ``` diff --git a/README.md b/README.md index e179385..ea92e84 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ -[![R-CMD-check](https://github.com/lewinfox/foodwebr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/lewinfox/foodwebr/actions/workflows/R-CMD-check.yaml) `foodwebr` makes it easy to visualise the dependency graph of a set of @@ -28,6 +27,8 @@ which call each other: ``` r library(foodwebr) +#> Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame' +#> when loading 'dplyr' f <- function() 1 g <- function() f() @@ -63,8 +64,7 @@ Plotting will draw the graph. plot(fw) ``` -
- + `foodweb()` looks at its calling environment by default. If you want to look at another environment you can either pass a function to the `FUN` @@ -116,8 +116,7 @@ if (requireNamespace("cowsay", quietly = TRUE)) { } ``` -
- + If we want to include *all* functions in the package, we can pass `filter = FALSE`: @@ -128,8 +127,7 @@ if (requireNamespace("cowsay", quietly = TRUE)) { } ``` -
- + ### `graphviz` as text @@ -168,7 +166,7 @@ if (requireNamespace("tidygraph", quietly = TRUE)) { #> # #> # A directed multigraph with 2 components #> # -#> # A tibble: 5 × 1 +#> # Node Data: 5 x 1 (active) #> name #> #> 1 f @@ -177,13 +175,13 @@ if (requireNamespace("tidygraph", quietly = TRUE)) { #> 4 i #> 5 j #> # -#> # A tibble: 7 × 2 +#> # Edge Data: 7 x 2 #> from to #> #> 1 2 1 #> 2 3 1 #> 3 3 2 -#> # ℹ 4 more rows +#> # … with 4 more rows ``` ## How does it work? @@ -192,11 +190,11 @@ Understanding the algorithm is important as there are some key limitations to be aware of. To identify the relationships between functions, `foodwebr`: -- Lists all the functions in an environment. -- Tokenises the `body()` of each function. -- Compares each token against the list of function names. -- If a token matches a function name, (i.e. the name of function B - appears in the body of function A), records a link from A to B. + - Lists all the functions in an environment. + - Tokenises the `body()` of each function. + - Compares each token against the list of function names. + - If a token matches a function name, (i.e. the name of function B + appears in the body of function A), records a link from A to B. This last point leads to the possibility of name masking, where a function contains an internal variable that matches the name of another @@ -230,9 +228,10 @@ If you know how to fix this please leave a comment in `foodwebr` is similar to these functions/packages: -- [`mvbutils::foodweb()`](): The OG of function dependency graphs in R, - and the inspiration for foodwebr. Less user-friendly output, in my - opinion. -- [`DependenciesGraphs`](https://github.com/datastorm-open/DependenciesGraphs): - Provides much nicer visualisations but does not appear to be actively - maintained. + - [`mvbutils::foodweb()`](): The OG of function dependency graphs in + R, and the inspiration for foodwebr. Less user-friendly output, in + my + opinion. + - [`DependenciesGraphs`](https://github.com/datastorm-open/DependenciesGraphs): + Provides much nicer visualisations but does not appear to be + actively maintained.