Learn R Programming

⚠️There's a newer version (3.2.0) of this package.Take me there.

lintr

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. Watch lintr in action in the following animation:

lintr is complementary to the styler package which automatically restyles code, eliminating some of the problems that lintr can detect.

Installation

Install the stable version from CRAN:

install.packages("lintr")

Or the development version from GitHub:

devtools::install_github("r-lib/lintr")

Usage

# in a project:
lintr::use_lintr(type = "tidyverse")
usethis::use_github_action("lint-project")
lintr::lint_dir()

# in a package:
lintr::use_lintr(type = "tidyverse")
usethis::use_github_action("lint")
lintr::lint_package()

You can also run lintr during continuous integration or within your IDE or text editor. See vignette("continuous-integration") and vignette("editors") for more details.

Without further configuration, this will run the default linters. See vignette("lintr") to learn how to modify these defaults.

Copy Link

Version

Install

install.packages('lintr')

Monthly Downloads

46,759

Version

3.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Jim Hester

Last Published

October 19th, 2022

Functions in lintr (3.0.2)

conjunct_test_linter

Force && conditions in expect_true(), expect_false() to be written separately
checkstyle_output

Checkstyle Report for lint results
configurable_linters

Configurable linters
absolute_path_linter

Absolute path linter
class_equals_linter

Block comparison of class with ==
any_duplicated_linter

Require usage of anyDuplicated() > 0 over any(duplicated(.))
commas_linter

Commas linter
closed_curly_linter

Closed curly linter
commented_code_linter

Commented code linter
clear_cache

Clear the lintr cache
common_mistakes_linters

Common mistake linters
condition_message_linter

Block usage of paste() and paste0() with messaging functions using ...
duplicate_argument_linter

Duplicate argument linter
efficiency_linters

Efficiency linters
consecutive_stopifnot_linter

Force consecutive calls to stopifnot into just one when possible
deprecated_linters

Deprecated linters
all_undesirable_functions

Default undesirable functions and operators
correctness_linters

Correctness linters
default_settings

Default lintr settings
default_linters

Default linters
cyclocomp_linter

Cyclomatic complexity linter
consistency_linters

Consistency linters
expect_lint

Lint expectation
expect_named_linter

Require usage of expect_named(x, n) over expect_equal(names(x), n)
expect_not_linter

Require usage of expect_false(.) over expect_true(!.)
exclude

Exclude lines or files from linting
equals_na_linter

Equality check with NA linter
expect_s4_class_linter

Require usage of expect_s4_class(x, k) over expect_true(is(x, k))
expect_true_false_linter

Require usage of expect_true(x) over expect_equal(x, TRUE)
expect_null_linter

expect_null Linter
expect_s3_class_linter

Require usage of expect_s3_class()
function_argument_linter

Function argument linter
fixed_regex_linter

Require usage of fixed=TRUE in regular expressions where appropriate
executing_linters

Code executing linters
expect_comparison_linter

Require usage of expect_gt(x, y) over expect_true(x > y) (and similar)
expect_lint_free

Test that the package is lint free
get_source_expressions

Parsed sourced file from a filename
function_left_parentheses_linter

Function left parentheses linter
lint

Lint a file, directory, or package
linters

Available linters
line_length_linter

Line length linter
lint-s3

Create a lint object
expect_length_linter

Require usage of expect_length(x, n) over expect_equal(length(x), n)
expect_identical_linter

Require usage of expect_identical(x, y) where appropriate
implicit_integer_linter

Implicit integer linter
infix_spaces_linter

Infix spaces linter
expect_type_linter

Require usage of expect_type(x, type) over expect_equal(typeof(x), type)
linters_with_defaults

Create a linter configuration based on defaults
ifelse_censor_linter

Block usage of ifelse where pmin or pmax is more appropriate
missing_argument_linter

Missing argument linter
extraction_operator_linter

Extraction operator linter
ids_with_token

Get parsed IDs by token
missing_package_linter

Missing package linter
numeric_leading_zero_linter

Require usage of a leading zero in all fractional numerics
linters_with_tags

Create a tag-based linter configuration
object_length_linter

Object length linter
open_curly_linter

Open curly linter
outer_negation_linter

Require usage of !any(.) over all(!.), !all(.) over any(!.)
lintr-package

Lintr
object_name_linter

Object name linter
literal_coercion_linter

Require usage of correctly-typed literals over literal coercions
object_usage_linter

Object usage linter
nonportable_path_linter

Non-portable path linter
pipe_call_linter

Pipe call linter
namespace_linter

Namespace linter
pipe_continuation_linter

Pipe continuation linter
modify_defaults

Modify lintr defaults
paren_body_linter

Parenthesis before body linter
paren_brace_linter

Parentheses before brace linter
normalize_exclusions

Normalize lint exclusions
is_lint_level

Is this an expression- or a file-level source object?
inner_combine_linter

Require c() to be applied before relatively expensive vectorized functions
read_settings

Read lintr settings
spaces_left_parentheses_linter

Spaces before parentheses linter
semicolon_linter

Semicolon linter
style_linters

Style linters
spaces_inside_linter

Spaces inside linter
single_quotes_linter

Single quotes linter
system_file_linter

Block usage of file.path() with system.file()
package_development_linters

Package development linters
package_hooks_linter

Package hooks linter
robustness_linters

Robustness linters
undesirable_operator_linter

Undesirable operator linter
regex_subset_linter

Require usage of direct methods for subsetting strings via regex.
sprintf_linter

sprintf linter
unneeded_concatenation_linter

Unneeded concatenation linter
redundant_ifelse_linter

Prevent ifelse() from being used to produce TRUE/FALSE or 1/0
todo_comment_linter

TODO comment linter
sarif_output

SARIF Report for lint results
trailing_blank_lines_linter

Trailing blank lines linter
nested_ifelse_linter

Block usage of nested ifelse() calls
no_tab_linter

No tab linter
parse_exclusions

read a source file and parse all the excluded lines from it
seq_linter

Sequence linter
xml_nodes_to_lints

Convert an XML node or nodeset into a Lint
undesirable_function_linter

Undesirable function linter
trailing_whitespace_linter

Trailing whitespace linter
readability_linters

Readability linters
paste_linter

Raise lints for several common poor usages of paste()
string_boundary_linter

Require usage of startsWith() and endsWith() over grepl()/substr() versions
strings_as_factors_linter

Identify cases where stringsAsFactors should be supplied explicitly
unreachable_code_linter

Block unreachable code and comments following return statements
yoda_test_linter

Block obvious "yoda tests"
unused_import_linter

Check that imported packages are actually used
vector_logic_linter

Enforce usage of scalar logical operators in conditional statements
use_lintr

Use lintr in your project
available_linters

Get Linter metadata from a package
T_and_F_symbol_linter

T and F symbol linter
brace_linter

Brace linter
any_is_na_linter

Require usage of anyNA over any(is.na(.))
best_practices_linters

Best practices linters
Linter

Create a linter closure
assignment_linter

Assignment linter
backport_linter

Backport linter