Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 655
csgillespie Avatar asked Mar 01 '11 20:03

csgillespie


People also ask

What does lintr do in R?

lintr provides static code analysis for R. It checks for adherence to a given style, identifying syntax errors and possible semantic issues, then reports them to you so you can take action.

What does Lintr mean?

Definition of linter 1 : a machine for removing linters. 2 linters plural : the fuzz of short fibers that adheres to cottonseed after ginning.

What is lint issue?

Lint, or a linter, is a static code analysis tool used to flag programming errors, bugs, stylistic errors and suspicious constructs. The term originates from a Unix utility that examined C language source code.


2 Answers

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.

like image 148
Gavin Simpson Avatar answered Oct 21 '22 14:10

Gavin Simpson


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.

like image 37
Jim Avatar answered Oct 21 '22 15:10

Jim