Skip to content

lintr

GitHub stars GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

lintr documentation

lintr - GitHub

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_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
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
- 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_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling R_LINTR and its pre/post commands None
R_LINTR_CONFIG_FILE lintr configuration file nameUse 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
R_LINTR_CLI_EXECUTABLE Override CLI executable ['lintr']

IDE Integration

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

IDE Extension Name Install
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 121 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 (file CLI lint mode)

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 :
RUN mkdir -p /home/r-library \
    && cp -r /usr/lib/R/library/ /home/r-library/ \
    && Rscript -e "install.packages(c('lintr','purrr'), repos = 'https://cloud.r-project.org/')" \
    && R -e "install.packages(list.dirs('/home/r-library',recursive = FALSE), repos = NULL, type = 'source')"