Writing a R lint program
When I program in python, I find using pylint very useful. However, when I program in R, there is nothing comparable.
As a small side project, I thought it would be fun to try and write a small lint program. Nothing too fancy, something along the lines of:
- Making sure function names are camel case 开发者_高级运维
- Average function length
- Detecting unused variables
- Spacing. For example,
function(x=1, y=2)
instead offunction(x=1,y=2)
However, I'm unsure of how to get started (I have started to look through the pylint soure code).
How should I get started? Are there standard programming techniques for this type of project? Any good resources that I should consider?
I would like to write the entire project in R.
Take a look at package codetools
that comes with R. Some details are found on the CRAN page for the package. The code in the package is run when you do R CMD check
for example so can catch unused variables etc. That might get you started on that aspect of rlint
.
To answer some of the other aspects... I'd start of writing simple functions that do one task, such as convert functions names to camel case. As you build up a body of small functions you can amalgamate them into a working lint wrapper function, whilst allowing users/developers flexibility to call the specific functions if they don't want the full lint behaviour.
lintr is an R package that does code linting for both style and possible semantic errors. It uses codetools under the hood as well as additional linting on top of it.
It also integrates with Emacs, Vim, Sublime Text and RStudio.
Recently, someone put up a lint package for R: http://cran.r-project.org/web/packages/lint/index.html
Looks like it's in early development. It's on Github here: https://github.com/halpo/lint.git
The "R CMD check" procedure might help you. One thing it does is find variables that are used without seeming to be initialised. This is often a typo. The code for that check procedure might help you.
I don't think its a small job though!
精彩评论