可视化 R 函数依赖关系 [英] Visualizing R Function Dependencies

查看:22
本文介绍了可视化 R 函数依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于想要可视化包依赖关系的人来说,有很多资源,但我对可视化包中的函数及其相互依赖关系特别感兴趣.有像 miniCRAN 这样的工具用于绘图包依赖关系,但是是否有任何东西可用于绘制包中的函数依赖关系?

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))

然后我只想要一个带有两个标记节点和连接它们的边的图,描述 func2func1 的依赖关系.

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.

谢谢.

推荐答案

我认为一个更好的选择(建立在 mvbutil 包的 foodweb 函数之上)是 DependenciesGraph 包,由 Github 上的 datastorm-open 在其更通用的基础上构建visNetwork 包.

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)

输出是一个 Web 服务器(在 RStudio 的查看器或单独的浏览器中查看),它允许您通过下拉菜单或单击它们来选择特定功能、放大和缩小、拖动它们,以及等等.对我来说,这比使用 base R 绘制 foodweb 函数的输出要好得多,因为通常很难让文本看起来很好地显示在每个节点的顶​​部,在 foodweb 图中,所有边缘的颜色都不同,在我看来,基本的 R 绘图函数并没有做很多工作来确保绘图的布局是可读或清晰的.

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.

与 mvbutil 的 foodweb 比较:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆