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

查看:24
本文介绍了可视化 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 功能之上)是由 datastorm-open 在 Github 上建立的 DependenciesGraph 包,建立在他们更通用的之上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)

输出是一个网络服务器(在 RStudio 的查看器中或在单独的浏览器中查看),它允许您通过下拉或单击来选择特定功能、放大和缩小、拖动它们,以及等等.对我来说,这比使用 base R 来绘制 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 的食物网的比较:

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天全站免登陆