Skip to content

lintr

lintr documentation

Configuration in MegaLinter

Variable Description Default value
R_LINTR_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
R_LINTR_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
R_LINTR_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
R_LINTR_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
file
R_LINTR_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".r", ".R", ".Rmd", ".RMD"]
R_LINTR_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
R_LINTR_PRE_COMMANDS List of bash commands to run before the linter None
R_LINTR_POST_COMMANDS List of bash commands to run after the linter None
R_LINTR_CONFIG_FILE lintr configuration file name
Use LINTER_DEFAULT to let the linter find it
.lintr
R_LINTR_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
R_LINTR_DISABLE_ERRORS Run linter but consider errors as warnings false
R_LINTR_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

IDE Integration

Use lintr in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
Atom Atom lintr Visit Web Site
Emacs flycheck Visit Web Site
rstudio Native Support Visit Web Site
Sublime Text SublimeLinter-contrib-lintr Visit Web Site
vim ale Visit Web Site
Visual Studio Code VsCode R LSP Install in VsCode

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 97 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .r, .R, .Rmd, .RMD

How the linting is performed

  • lintr is called one time by identified file

Example calls

R --slave -e "errors <- lintr::lint('myfile.r'); print(errors); quit(save = 'no', status = if (length(errors) > 0) 1 else 0) "

Help content

No documentation for ‘lintr’ in specified packages and libraries:
you could try ‘??lintr’

Installation on mega-linter Docker image

  • Dockerfile commands :
FROM ghcr.io/assignuser/lintr-lib:0.2.0 as lintr-lib
COPY --from=lintr-lib /usr/lib/R/library/ /home/r-library
RUN R -e "install.packages(list.dirs('/home/r-library',recursive = FALSE), repos = NULL, type = 'source')"

Example success log

Results of lintr linter (version 2.0.1.9000)
See documentation on https://megalinter.github.io/descriptors/r_lintr/
-----------------------------------------------

[SUCCESS] .automation/test/r/r_good_1.r
    Warning message:
    In readLines(filename) :
      incomplete final line found on '.automation/test/r/r_good_1.r'

Example error log

Results of lintr linter (version 2.0.1.9000)
See documentation on https://megalinter.github.io/descriptors/r_lintr/
-----------------------------------------------

[ERROR] .automation/test/r/r_bad_1.r
    style:.automation/test/r/r_bad_1.r:8:3::Use <-, not =, for assignment.
    style:.automation/test/r/r_bad_1.r:8:14::Remove spaces before the left parenthesis in a function call.
    style:.automation/test/r/r_bad_1.r:8:17::Commas should always have a space after.
    style:.automation/test/r/r_bad_1.r:8:22::There should be a space between right parenthesis and an opening curly brace.
    style:.automation/test/r/r_bad_1.r:8:23::Opening curly braces should never go on their own line and should always be followed by a new line.
    style:.automation/test/r/r_bad_1.r:8:24::Closing curly-braces should always be on their own line, unless it's followed by an else.
    style:.automation/test/r/r_bad_1.r:11:3::Commented code should be removed.
    style:.automation/test/r/r_bad_1.r:21:1::functions should have cyclomatic complexity of less than 15, this has 22.
    style:.automation/test/r/r_bad_1.r:21:1::Variable and function names should not be longer than 30 characters.
    style:.automation/test/r/r_bad_1.r:21:1::Variable and function name style should be snake_case.
    style:.automation/test/r/r_bad_1.r:22:1::Opening curly braces should never go on their own line and should always be followed by a new line.
    style:.automation/test/r/r_bad_1.r:24:1::Lines should not be more than 80 characters.
    style:.automation/test/r/r_bad_1.r:24:44::Put spaces around all infix operators.
    warning:.automation/test/r/r_bad_1.r:24:57::Use is.na rather than == NA.
    style:.automation/test/r/r_bad_1.r:24:64::Opening curly braces should never go on their own line and should always be followed by a new line.
    style:.automation/test/r/r_bad_1.r:24:69::Closing curly-braces should always be on their own line, unless it's followed by an else.
    style:.automation/test/r/r_bad_1.r:24:76::Opening curly braces should never go on their own line and should always be followed by a new line.
    style:.automation/test/r/r_bad_1.r:24:82::Closing curly-braces should always be on their own line, unless it's followed by an else.
    style:.automation/test/r/r_bad_1.r:31:3::Do not place spaces around code in parentheses or square brackets.
    warning:.automation/test/r/r_bad_1.r:32:1::Avoid 1:length(...) expressions, use seq_len.
    style:.automation/test/r/r_bad_1.r:32:37::Put spaces around all infix operators.
    style:.automation/test/r/r_bad_1.r:32:43::`%>%` should always have a space before it and a new line after it, unless the full pipeline fits on one line.
    style:.automation/test/r/r_bad_1.r:36:9::Only use double-quotes.
    style:.automation/test/r/r_bad_1.r:40:8::Put spaces around all infix operators.
    style:.automation/test/r/r_bad_1.r:40:9::Place a space before left parenthesis, except in a function call.
    style:.automation/test/r/r_bad_1.r:43:1::Trailing blank lines are superfluous.