How do you calculate cyclomatic complexity for R functions?
Also, I just found a new package called cyclocomp (released 2016). Check it out!
Calculate Cyclomatic complex when it comes to a recursion function
See https://en.m.wikipedia.org/wiki/Cyclomatic_complexity. Recursion by definition does not impact cyclomatic complexity and the tools measuring it also do not actually 'run' the code and measure it. This is because the original definition of McCabe states that CC is the number of possible path that the code can take, and that's about it. If you are still not convinced , just give it a different name, say recursive cylcomatic complexity, and measure it, by counting the actual number of invocations at runtime. Refer: https://www.guru99.com/cyclomatic-complexity.html
How to calculate cyclomatic complexity of a Clojure function?
Macros are an abstraction and should not contributed to the CC calculation, any more than a function call would.
That said, I don't think that CC is particularly interesting for Clojure. I would be more interested in something that measured overuse of mutability.
What is the highest Cyclomatic Complexity of any function you maintain? And how would you go about refactoring it?
This is kid stuff compared to some 1970s vintage COBOL I worked on some years ago. We used the original McCabe tool to graphically display the CC for some of the code. The print out was pure black because the lines showing the functional paths were so densely packed and spaghetti-like. I don't have a figure but it had to be way higher than 171.
What to do
Per Code Complete (first edition):
If the score is:
- 0-5 - the routine is probably fine
- 6-10 - start to think about ways to simplify the routine
- 10+ - break part of the routine into a second routine and call it from the first routine
Might be a good idea to write unit tests as you break up the original routine.
Related Topics
Running Cor() (Or Any Variant) Over a Sparse Matrix in R
Control Alignment of Two Side-By-Side Plots in Knitr
How to Specify (Non-R) Library Path for Dynamic Library Loading in R
Findinterval() with Right-Closed Intervals
Error: Zipping Up Workbook Failed When Trying to Write.Xlsx
How to Plot a Histogram of a Long-Tailed Data Using R
Subset Rows with (1) All and (2) Any Columns Larger Than a Specific Value
How to Know If R Is Running on 64 Bits Versus 32
R "Stats" Citation for a Scientific Paper
Most Mature Sparse Matrix Package for R
How to Add Chapter Bibliographies Using Bookdown
What Is the Knitr Equivalent of 'R Cmd Sweave Myfile.Rnw'
How to Replicate Knit HTML in a Command Line
Trying to Find Row Associated with Max Value in Dataframe R
What Techniques Exists in R to Visualize a "Distance Matrix"
What Is a Fast Way to Set Debugging Code at a Given Line in a Function