Visualizing R code with a flow chart
Asked Answered
E

2

12

Are there any tools that can visualize R code?

I have some very complex R code split between several scripts that I need to understand. Part of the difficulty of this is that there are so many nested functions and variables that it's proving extremely slow going to go through it manually and figure out what connects to what.

I think my task might be easier if there were some way to generate a flow chart from R code, so that I can see it all at once. Of course, I can just draw out a map as I go through the code, but shouldn't it be programatically possible to do this? Are there any existing tools that can do it?

I have found a program called R AnalyticFlow, but it seems to MAKE scripts using a GUI, whereas I want something that can take code and make it into the type of thing that one would draw in AnalyticFlow.

Echols answered 21/2, 2018 at 21:42 Comment(5)
For reference, there is a package called snakefood that implements this for Python: furius.ca/snakefood . The graphing you can do (manually) in GraphViz Dot. The answers here might be helpful: #44143610Laughingstock
That looks cool, I will check it out. If it also can visualize input file dependencies, it's just what I need.Echols
Check out CodeDepends , read this vignette and scroll until you see charts : cran.r-project.org/web/packages/CodeDepends/vignettes/…Johannejohannes
The drake package sounds like it might be relevant for you. It helps generate dependency graphs between your scripts to see what is out of dat.e github.com/ropensci/drakeBlakeley
Thanks, I will try that. I never did manage to get CodeDepends working, but I still have this need.Echols
S
3

You can visualize your functions in a easy way using the mvbills package.

Install/import

install.packages("mvbutils", dependencies = TRUE)
library(mvbutils)

And use

foodweb(where = environment())

In my case, an example of output would be:

enter image description here

Or if it's a package (or you just want to try other option), you can use the DependenciesGraphs package.

Spallation answered 19/12, 2019 at 14:54 Comment(0)
L
2

Even though this question is already a bit old there is a nice R-package called flow that might be very useful for the task:

https://moodymudskipper.github.io/flow/index.html

It graphically visualizes functions, if-then-else statements and more.

Letty answered 4/2, 2022 at 12:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.