一句话:提出 flowR,一个面向 R 的静态程序切片与数据流分析工具,集成到 VS Code 辅助脚本理解与维护。
研究者常用 R 脚本做统计分析与可视化,但脚本常因分析、绘图混杂而难以理解维护,且缺乏分析工具。作者提出 flowR:面向 R 的静态程序切片器与数据流分析器,可集成到 Visual Studio Code。它先静态构建细粒度数据流图,支持循环、函数调用、副作用、source 外部文件及 R 原语重定义;再在图上求解可达性,得到用户感兴趣变量对应的程序切片,并以多种交互方式呈现。评估显示,在给定数据流图上计算切片平均约 16 ms,可减少约 94% 的 token,帮助聚焦相关代码。
Context Many researchers rely on the R programming language to perform their statistical analyses and visualizations in the form of R scripts. However, recent research and experience show, that many of these scripts contain problems. From being hard to comprehend by combining several analyses and plots into a single source file to being non-reproducible, with a lack of analysis tools supporting the writing of correct and maintainable code. Objective In this work, we address the problem of comprehending and maintaining R scripts by proposing flowR, a program slicer and static dataflow analyzer for the R programming language, which can be integrated directly into Visual Studio Code. Given a set of variables of interest, like the generation of a single figure in a script, flowR automatically reduces the program to the parts relevant for the output of interest, like the value of a variable. Method First, we use static program analysis to construct a detailed dataflow graph of the R script. The analysis supports loops, function calls, side effects, sourcing external files, and even redefinitions of R's primitive constructs. Subsequently, we calculate the program slice by solving a reachability problem on the graph, collecting all required parts and presenting them to the user. Results Providing several interactive ways of slicing the program, we require an average of 16 ms to calculate the slice on a given dataflow graph, reducing the code by around 94% of tokens.