Writing a R lint program
Asked Answered
D

4

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.

Demoniac answered 1/3, 2011 at 20:47 Comment(3)
Did you ever make any progress on this project?Savonarola
@Savonarola I spent a week or so taking apart the codetools package. I learnt alot, but didn't make any serious progress. Hopefully this summer......Demoniac
Good luck! I don't have any time to offer to contribute, but would love to have an rlint tool on hand!Savonarola
S
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.

Satiable answered 1/3, 2011 at 20:58 Comment(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.Demoniac
@Demoniac Welcome. For the unused variable bit and perhaps a few other things yes, but not the camelCase or spacing as these are stylistic points.Satiable
F
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.

Floodlight answered 6/3, 2015 at 16:14 Comment(0)
H
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

Heparin answered 23/2, 2013 at 4:42 Comment(1)
This package was removed from CRAN, at the author/maintainer's request.Reredos
L
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!

Livvyy answered 1/3, 2011 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.