15

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 of function(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.

3
  • Did you ever make any progress on this project?
    – fmark
    May 4, 2012 at 1:20
  • @fmark I spent a week or so taking apart the codetools package. I learnt alot, but didn't make any serious progress. Hopefully this summer...... May 4, 2012 at 13:40
  • Good luck! I don't have any time to offer to contribute, but would love to have an rlint tool on hand!
    – fmark
    May 6, 2012 at 10:18

4 Answers 4

12

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.

2
  • Thanks. I've just had a look at the source code, and it seems to be that a lot of work has already been done. Mar 1, 2011 at 21:02
  • @csgillespie Welcome. For the unused variable bit and perhaps a few other things yes, but not the camelCase or spacing as these are stylistic points. Mar 1, 2011 at 21:09
12

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.

8

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

1
  • 1
    This package was removed from CRAN, at the author/maintainer's request.
    – mjv
    Apr 22, 2017 at 1:17
5

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.