Visualizing R Function Dependencies

前端 未结 2 1580
耶瑟儿~
耶瑟儿~ 2020-12-08 16:36

There are a lot of resources for people who want to visualize package dependencies, but I\'m interested specifically in visualizing functions within a package and their depe

相关标签:
2条回答
  • 2020-12-08 16:54

    I suggest using the foodweb function from mvbutils package.

    e <- new.env()
    e$func1 <- function(n) return(LETTERS[n])
    e$func2 <- function(n) return(func1(n%%26+1))
    
    library(mvbutils)
    foodweb(where = e)
    

    See examples under ?mvbutils for more.

    0 讨论(0)
  • 2020-12-08 17:03

    I think a better option (built on top of the mvbutil package's foodweb functions) is the DependenciesGraph package built by datastorm-open on Github on top of their more general visNetwork package.

    • DependenciesGraph : an R package for dependencies visualization between packages and functions

    In my example, I have been visualizing my own package for maintenance and development and have been very pleased with the results.

    library(DependenciesGraph)
    library(QualtricsTools) # A package I'm developing
    deps <- funDependencies("package:QualtricsTools", "generate_split_coded_comments")
    plot(deps)
    

    Dependency Graph generated by DependenciesGraph

    The output is a web server (either viewed in RStudio's viewer or in a separate browser) that allows you to choose specific functions through a drop down or by clicking on them, to zoom in and out, to drag them around, and so forth. To me, this is much nicer than using base R to plot the output of the foodweb function because often it is difficult to get the text to look nice displayed on top of each node, all the edges are jarringly colored differently in a foodweb plot, and it doesn't appear to me that the base R plot functions are doing very much to ensure that the layout of the plot is readable or clear.

    A comparison against mvbutil's foodweb:

    library(mvbutils)
    library(QualtricsTools) 
    deps <- foodweb(where="package:QualtricsTools", prune='make_split_coded_comments')
    plot(deps)
    

    A foodweb dependency graph of make_split_coded_comments

    (Sorry there's a discrepancy in the names, they really are the same function, I just happened to have renamed the function between making these two plots).

    0 讨论(0)
提交回复
热议问题