Last chance! 50% off unlimited learning
Sale ends in
{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.
Install the stable version from CRAN:
install.packages("lintr")
Or the development version from GitHub:
# install.packages("remotes")
remotes::install_github("r-lib/lintr")
And then you can create a configuration file and run selected linters:
lintr::use_lintr(type = "tidyverse")
# in a project:
lintr::lint_dir()
# in a package:
lintr::lint_package()
To see a list of linters included for each configuration:
# tidyverse (default)
names(lintr::linters_with_defaults())
# full
names(lintr::all_linters())
{usethis}
provides helper functions to generate lint workflows for GitHub Actions:
# in a project:
usethis::use_github_action("lint-project")
# in a package:
usethis::use_github_action("lint")
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.
Please note that the lintr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
install.packages('lintr')
paste()
and paste0()
with messaging functions using ...
==
expect_identical(x, y)
where appropriateexpect_length(x, n)
over expect_equal(length(x), n)
expect_gt(x, y)
over expect_true(x > y)
(and similar)expect_null
for checking NULL
expect_s3_class()
&&
conditions in expect_true()
and expect_false()
to be written separately{}
fixed=TRUE
in regular expressions where appropriateifelse()
where pmin()
or pmax()
is more appropriateexpect_named(x, n)
over expect_equal(names(x), n)
expect_false(x)
over expect_true(!x)
c()
to be applied before relatively expensive vectorized functionsis.numeric(x) || is.integer(x)
to just use is.numeric(x)
expect_true(x)
over expect_equal(x, TRUE)
expect_s4_class(x, k)
over expect_true(is(x, k))
lengths()
where possibleexpect_type(x, type)
over expect_equal(typeof(x), type)
colSums(x)
or rowSums(x)
over apply(x, ., sum)
paste()
==
, !=
on logical vectorsstringsAsFactors
should be supplied explicitlyifelse()
callslint
objectSTR_CONST
nodesif
conditional statementsfile.path()
with system.file()
sprintf()
callsstartsWith()
and endsWith()
over grepl()
/substr()
versionsifelse()
from being used to produce TRUE
/FALSE
or 1
/0
!any(x)
over all(!x)
, !all(x)
over any(!x)
sort()
over .[order(.)]
linter
closureanyDuplicated(x) > 0
over any(duplicated(x))
anyNA(x)
over any(is.na(x))
T
and F
symbol linter