【发布时间】:2019-05-22 21:59:50
【问题描述】:
我通常编写具有多个功能的模块化脚本。当事情发展时,很难跟踪哪个函数调用了哪个(将它们命名为 01-first.R 02-second.R 并不总是可行的,我宁愿不将其用作最终解决方案)。
这是一个潜在的script.R 示例,它将运行 3 个带有帮助程序的“主要”函数。
first <- function(...){
# do data things
return(first_output)
}
second <- function(first_output){
# do data things
# call helper
x <- helper(...)
# do things to x
return(second_output)
}
third <- function(second_output){
# do data things
return(result)
}
我很想得到这样的东西
可以在 R 中使用 diagrammeR 包生成。
grViz("
digraph boxes_and_circles {
# a 'graph' statement
graph [overlap = true, fontsize = 10]
# several 'node' statements
node [shape = box,
fontname = Helvetica]
first; second; helper; third;
# several 'edge' statements
first->second second->helper
helper -> second
second->third
third -> result
}
")
就是这样(什么函数调用另一个函数)会很棒。真正令人敬畏的是一种根据参数显示分叉类型的方法(例如,默认情况下first 有一个go_to_third=FALSE,但如果go_to_third=TRUE 它直接跳转到third)。拥有函数正在处理的对象类也很棒。
我已经检查了这个问题Visualizing R Function Dependencies 我想知道是否有更好的方法来做到这一点,视觉上更好。
这个问题与 MATLAB Automatically generating a diagram of function calls in MATLAB 中的这个问题类似,我可以从 R 外部使用 GraphViz 进行破解。
【问题讨论】:
标签: r graphviz flowchart diagrammer