【问题标题】:Script to Flowchart in RR中的流程图脚本
【发布时间】: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


    【解决方案1】:

    不完全是你所追求的,但我一直在开发一个库来对 dplyr 管道进行可视化:

    https://github.com/terminological/dtrackr

    它可以或多或少地做你想做的事,但在更精细的层面上。如有任何反馈,我将不胜感激。

    【讨论】:

    • 哦,哇,这非常有用(不是我真正想要的,但你已经做到了!)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多