Skip to content

Commit

Permalink
Revert to old README that includes the images
Browse files Browse the repository at this point in the history
  • Loading branch information
lewinfox committed Sep 27, 2023
1 parent 233e9d8 commit dfee657
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
13 changes: 2 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
output: github_document
always_allow_html: true
---

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand All @@ -18,7 +17,6 @@ knitr::opts_chunk$set(
# foodwebr

<!-- badges: start -->
[![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)
<!-- badges: end -->

`foodwebr` makes it easy to visualise the dependency graph of a set of functions (i.e. who calls
Expand All @@ -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()
```

Expand Down
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<!-- badges: start -->

[![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)
<!-- badges: end -->

`foodwebr` makes it easy to visualise the dependency graph of a set of
Expand All @@ -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()
Expand Down Expand Up @@ -63,8 +64,7 @@ Plotting will draw the graph.
plot(fw)
```

<div class="grViz html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-bebf81d879e077792911" style="width:100%;height:192px;"></div>
<script type="application/json" data-for="htmlwidget-bebf81d879e077792911">{"x":{"diagram":"digraph \"foodweb\" {\n \"f()\"\n \"g()\" -> { \"f()\" }\n \"h()\" -> { \"f()\", \"g()\" }\n \"i()\" -> { \"f()\", \"g()\", \"h()\" }\n \"j()\" -> { \"j()\" }\n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
<img src="man/figures/README-foodweb-plot-1.png" width="100%" />

`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`
Expand Down Expand Up @@ -116,8 +116,7 @@ if (requireNamespace("cowsay", quietly = TRUE)) {
}
```

<div class="grViz html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-404eca409fce9f872862" style="width:100%;height:192px;"></div>
<script type="application/json" data-for="htmlwidget-404eca409fce9f872862">{"x":{"diagram":"digraph \"foodweb\" {\n \"say()\" -> { \"check_color()\", \"check4pkg()\", \"get_who()\" }\n \"check_color()\" -> { \"check4pkg()\" }\n \"check4pkg()\"\n \"get_who()\" -> { \"make_longcat()\" }\n \"make_longcat()\"\n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
<img src="man/figures/README-foodweb-plot-package-1.png" width="100%" />

If we want to include *all* functions in the package, we can pass
`filter = FALSE`:
Expand All @@ -128,8 +127,7 @@ if (requireNamespace("cowsay", quietly = TRUE)) {
}
```

<div class="grViz html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-2f7491812a89da2d9ba6" style="width:100%;height:192px;"></div>
<script type="application/json" data-for="htmlwidget-2f7491812a89da2d9ba6">{"x":{"diagram":"digraph \"foodweb\" {\n \"check_color()\" -> { \"check4pkg()\" }\n \"check4pkg()\"\n \"endless_horse()\" -> { \"get_who()\" }\n \"get_who()\" -> { \"make_longcat()\" }\n \"make_longcat()\"\n \"say()\" -> { \"check_color()\", \"check4pkg()\", \"get_who()\" }\n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
<img src="man/figures/README-foodweb-plot-package-no-filter-1.png" width="100%" />

### `graphviz` as text

Expand Down Expand Up @@ -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
#> <chr>
#> 1 f
Expand All @@ -177,13 +175,13 @@ if (requireNamespace("tidygraph", quietly = TRUE)) {
#> 4 i
#> 5 j
#> #
#> # A tibble: 7 × 2
#> # Edge Data: 7 x 2
#> from to
#> <int> <int>
#> 1 2 1
#> 2 3 1
#> 3 3 2
#> # 4 more rows
#> # … with 4 more rows
```

## How does it work?
Expand All @@ -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
Expand Down Expand Up @@ -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.

0 comments on commit dfee657

Please sign in to comment.