可视化R函数依赖关系 [英] Visualizing R Function Dependencies
问题描述
func1 < - function(n)return(LETTERS [n])
func2 < - function(n)return(func1(n %% 26 + 1))
$ c $然后我只想要一个带有两个标签节点和连接它们的边的图,它描述了 func2 的依赖关系。 code>在 func1
上。
我认为这里有很多的软件包会有很多功能依赖,这样的实用程序可以帮助理解/组织/重构/等等。
谢谢。
解决方案在mvbutil软件包的foodweb函数的顶部)是通过datastorm构建的DependenciesGraph包 - 在Github上打开,在它们的更一般的 visNetwork 软件包。
- DependenciesGraph :用于包和函数之间的依赖关系可视化的R包
在我的示例中,我一直在可视化我自己的包以进行维护和发展,并对结果非常满意。
library(DependenciesGraph)
library(QualtricsTools)#我正在开发一个包
deps< - funDependencies(package:QualtricsTools,generate_split_coded_comments)
plot(deps)
输出是一个web服务器(可以在RStudio的查看器中查看,也可以在单独的浏览器中查看),允许您通过下拉或点击选择特定的功能,放大和缩小,拖动它们等等。对我来说,这比使用基本R来绘制foodweb函数的输出要好得多,因为通常很难让文本看起来很好显示在每个节点的顶部,所有的边缘在foodweb图中都有不同的颜色,并且在我看来,基本的R绘图功能在很大程度上确保绘图的布局可读或清晰。
与mvbutil的foodweb比较:
library(mvbutils)
library(QualtricsTools)
deps < - foodweb(where =package:QualtricsTools,prune ='make_split_coded_comments')
plot(deps)
(抱歉,名称存在差异,它们实际上是相同的功能,我只是在重复这两个图之间重新命名了这个函数)。
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 dependencies on one another. There are tools like miniCRAN for graphing package dependencies, but is there anything available to graph function dependencies within a package?
For example, suppose I only have two functions in my package.
func1 <- function(n) return(LETTERS[n])
func2 <- function(n) return(func1(n%%26+1))
Then I would just want a graph with two labeled nodes and an edge connecting them, depicting the dependency of func2
on func1
.
I would think there are a lot of packages out there that have really hairy functional dependencies that such a utility could help in understanding/organizing/refactoring/etc.
Thanks.
解决方案 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)
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)
(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).
这篇关于可视化R函数依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!