In MATLAB, I can get a quantification of how succinct my code is by using the following code:
t = mtree('myCode.m','-file');
length(t.nodesize)
As CODY (http://www.mathworks.com/matlabcentral/about/cody/) describes it:
Cody uses a node-count calculation to determine the solution size based on the number of nodes in the parse tree. Think of size as code length. Writing succinct code earns you a better result. Comments do not contribute to code size.
To illustrate how Cody determines size, here are two solutions to the plus-one problem.
Solution 1 has a size of 12:
function y = plus_one(x)
y = x+1;
end
Solution 2 has a size of 16:
function y = plus_one(x)
z = x;
y = z+1;
end
Is there any way to get a similar calculation for R code? Are there any other quantifiable metrics for code quality in R? MATLAB also can measure McCabe complexity, for example:
mlint -cyc myCode.m