问题描述
衡量一个功能可以使用多少个分支。是否有用于计算R功能的现有功能/工具?如果不是这样,建议就最好的方式写出建议。
Cyclomatic complexity measures how many possible branches can be taken through a function. Is there an existing function/tool to calculate it for R functions? If not, suggestions are appreciated for the best way to write one.
一个便宜的开始是算出所有的出现
, ifelse
或 switch
。但是,要获得真实的答案,您需要了解分支的开始和结束时间,这要困难得多。
A cheap start towards this would be to count up all the occurences of if
, ifelse
or switch
within your function. To get a real answer though, you need to understand when branches start and end, which is much harder. Maybe some R parsing tools would get us started?
推荐答案
我还发现了一个名为cyclocomp的新程序包(2016年发布)。看看吧!
Also, I just found a new package called cyclocomp (released 2016). Check it out!
这篇关于如何计算R函数的圈复杂度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!