diff --git a/dev/articles/creating_linters.html b/dev/articles/creating_linters.html index bdd8d9fa7..d0c8d222e 100644 --- a/dev/articles/creating_linters.html +++ b/dev/articles/creating_linters.html @@ -87,7 +87,7 @@
vignettes/creating_linters.Rmd
creating_linters.Rmd
tmp <- withr::local_tempfile(lines = "c('a', 'b')")
expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file169079f85809': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file171252e2d3b3': No such file or directory
#> Error in file(con, "r"): cannot open the connection
writeLines(as.character(expr_as_xml))
#> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found
@@ -118,7 +118,7 @@ Examples# more importantly, extract strings under R>=4 raw strings
tmp4.0 <- withr::local_tempfile(lines = "c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')")
expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file16904e7f04a9': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file171227c8163b': No such file or directory
#> Error in file(con, "r"): cannot open the connection
writeLines(as.character(expr_as_xml4.0))
#> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found
diff --git a/dev/reference/get_source_expressions.html b/dev/reference/get_source_expressions.html
index f942fa73c..dc5c86072 100644
--- a/dev/reference/get_source_expressions.html
+++ b/dev/reference/get_source_expressions.html
@@ -134,7 +134,7 @@ Details
Examples
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
get_source_expressions(tmp)
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file16907e2a0f4b': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file17124b066f19': No such file or directory
#> Error in file(con, "r"): cannot open the connection
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
source_exprs <- get_source_expressions(tmp)
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file1690a30eb69': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file1712f459584': No such file or directory
#> Error in file(con, "r"): cannot open the connection
ids_with_token(source_exprs$expressions[[1L]], value = "SYMBOL")
#> Error in eval(expr, envir, enclos): object 'source_exprs' not found
diff --git a/dev/reference/is_lint_level.html b/dev/reference/is_lint_level.html
index e86227c16..a21d0406e 100644
--- a/dev/reference/is_lint_level.html
+++ b/dev/reference/is_lint_level.html
@@ -92,7 +92,7 @@ ArgumentsExamples
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
source_exprs <- get_source_expressions(tmp)
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file16904d2e0e96': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file17126e1d4b74': No such file or directory
#> Error in file(con, "r"): cannot open the connection
is_lint_level(source_exprs$expressions[[1L]], level = "expression")
#> Error in eval(expr, envir, enclos): object 'source_exprs' not found
diff --git a/dev/reference/lint.html b/dev/reference/lint.html
index b359bb912..4c349f83a 100644
--- a/dev/reference/lint.html
+++ b/dev/reference/lint.html
@@ -183,7 +183,7 @@ Details
Examples
f <- withr::local_tempfile(lines = "a=1", fileext = "R")
lint(f) # linting a file
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file169025dd8bedR': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file17124ebea49R': No such file or directory
#> Error in file(con, "r"): cannot open the connection
lint("a = 123\n") # linting inline-code
#> ::warning file=<text>,line=1,col=3::file=<text>,line=1,col=3,[assignment_linter] Use <-, not =, for assignment.
diff --git a/dev/reference/linters_with_defaults.html b/dev/reference/linters_with_defaults.html
index 86b3e237a..d5597f0b6 100644
--- a/dev/reference/linters_with_defaults.html
+++ b/dev/reference/linters_with_defaults.html
@@ -106,7 +106,7 @@ Examples# When using interactively you will usually pass the result onto `lint` or `lint_package()`
f <- withr::local_tempfile(lines = "my_slightly_long_variable_name <- 2.3", fileext = "R")
lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120)))
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file169075a66c88R': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file17123fd04efR': No such file or directory
#> Error in file(con, "r"): cannot open the connection
# the default linter list with a different line length cutoff
diff --git a/dev/reference/trailing_blank_lines_linter.html b/dev/reference/trailing_blank_lines_linter.html
index fff3db44e..7d89ca05f 100644
--- a/dev/reference/trailing_blank_lines_linter.html
+++ b/dev/reference/trailing_blank_lines_linter.html
@@ -85,25 +85,25 @@ Examples# will produce lints
f <- withr::local_tempfile(lines = "x <- 1\n")
readLines(f)
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file16907f79eb4': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file171213176593': No such file or directory
#> Error in file(con, "r"): cannot open the connection
lint(
filename = f,
linters = trailing_blank_lines_linter()
)
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file16907f79eb4': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file171213176593': No such file or directory
#> Error in file(con, "r"): cannot open the connection
# okay
f <- withr::local_tempfile(lines = "x <- 1")
readLines(f)
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file1690131a9257': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file17122cbc4af9': No such file or directory
#> Error in file(con, "r"): cannot open the connection
lint(
filename = f,
linters = trailing_blank_lines_linter()
)
-#> Warning: cannot open file '/tmp/RtmpyuoqE0/file1690131a9257': No such file or directory
+#> Warning: cannot open file '/tmp/RtmpWInPUR/file17122cbc4af9': No such file or directory
#> Error in file(con, "r"): cannot open the connection
diff --git a/dev/search.json b/dev/search.json
index ee851b73b..32724f1e3 100644
--- a/dev/search.json
+++ b/dev/search.json
@@ -1 +1 @@
-[{"path":[]},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement james.f.hester@gmail.com. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with lintr","title":"Getting help with lintr","text":"Thanks using lintr. filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"making-a-reproducible-example","dir":"","previous_headings":"","what":"Making a reproducible example","title":"Getting help with lintr","text":"Start making minimal reproducible example using reprex package. use reprex effectivly, check Get help! section tidyverse site. useful function create reprexes lintr issues lint(). can include code doesn’t lint expected linter question. example, code question contains characters need escaped, consider using raw strings instead save headache figuring multiple levels escapes.","code":"library(lintr) lint( text = \"x = 1\", linters = assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"asking-for-help","dir":"","previous_headings":"","what":"Asking for help","title":"Getting help with lintr","text":"Armed reprex, next step figure ask. ’s clarification question (e.g. don’t know exclude certain files lint workflow), start community.rstudio.com, /StackOverflow. people answer questions.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"filing-an-issue","dir":"","previous_headings":"","what":"Filing an issue","title":"Getting help with lintr","text":"’s bug, can create issue reprex. ’s false positive false negative lint, can either create issue reprex lintr repository, discuss underlying style guide respective repository. opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed. Thanks help!","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions","dir":"Articles","previous_headings":"For packages","what":"GitHub Actions","title":"Continuous integration","text":"package GitHub, easiest way GitHub Actions. workflow configuration files use YAML syntax. usethis package great functionality can help workflow files. straightforward way add lintr workflow package use r-lib/actions’s lint example. usethis, need call create workflow file called lint.yaml place correct location, namely .github/workflows directory repository. file configures steps required run lintr::lint_package() package. Alternatively can use eponymous lint-changed-files.yaml lint changed files: Comments commit pull request printed annotations along side status check GitHub. want builds produce error instead just warning, can set environment variable LINTR_ERROR_ON_LINT=true. set default r-lib/actions’s lint.yaml lint-changed-files.yaml. Note kill R process case lint. project subdirectory like use GitHub Actions annotations, can set options(lintr.github_annotation_project_dir = \"path//project\") make sure annotations point correct paths.","code":"usethis::use_github_action(\"lint\") usethis::use_github_action(\"lint-changed-files\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"travis-ci","dir":"Articles","previous_headings":"For packages","what":"Travis CI","title":"Continuous integration","text":"want run lintr Travis-CI, need Travis install package first. can done adding following line .travis.yml recommend running lintr::lint_package() after_success step build process: lints found commit pull request printed Travis-CI. environment variable LINTR_ERROR_ON_LINT mentioned GitHub actions also works Travis CI builds.","code":"r_github_packages: - r-lib/lintr after_success: - R CMD INSTALL $PKG_TARBALL - Rscript -e 'lintr::lint_package()'"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"for-projects","dir":"Articles","previous_headings":"","what":"For projects","title":"Continuous integration","text":"limited using lintr packages – can use combination continuous integration project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions-1","dir":"Articles","previous_headings":"For projects","what":"GitHub Actions","title":"Continuous integration","text":"project GitHub, take advantage GitHub Actions usethis functionality. r-lib/actions includes lint-project example, can use calling:","code":"usethis::use_github_action(\"lint-project\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"super-linter","dir":"Articles","previous_headings":"For projects","what":"Super-Linter","title":"Continuous integration","text":"lintr powers R lints Super-Linter MegaLinter, provide unified linting experience across many languages. Specifically, execute lintr::lint() R R Markdown files included given project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-the-linter","dir":"Articles","previous_headings":"","what":"Writing the linter","title":"Creating new linters","text":"Describe linter, giving title briefly covering usages discouraged linter active. lines (1) generate Tags section documentation linter1; (2) link full table available linters; (3) mark function export. unfamiliar probably (1), can skipped outside lintr . Next, define name new linter. convention suffix linter names _linter. _linter functions function factories return closure actual linting function. define additional parameters useful linter function declaration (see, e.g. assignment_linter), pipe_call_linter requires additional arguments. core linter logic. xpath XPath expression expressions matching discouraged usage. xpath saved inside factory code (opposed inside linter ) efficiency. Often, xpath somewhat complicated / involve assembly code using paste() glue::glue()[^See infix_spaces_linter() example ], case preferable execute code creating linter; cached XPath re-used expression file linter run. Let’s examine XPath bit closely: Taken together, means want match expr nodes preceded %>% infix operator whose first child node name. maps pretty closely description pipe_call_linter looking , subtlety mapping R code ’re used show XML representation. expr nodes particular take practice get accustomed – use plentiful XPath-based linters lintr guide get extra practice2. Note: xml2 implements XPath 1.0, lacks helpful features available XPath 2.0. closure. called source_expression variable contains top level expressions file linted. call Linter() gives closure class ‘linter’ (also guesses name linter; see ?Linter details). raw text expression available source_file$content. However, generally possible implement linters raw text – consider equals_na_linter. just look == NA text file, ’ll generate many false positives, e.g. comments (# note: .na() proper way check == NA) inside character literals (warning(\"use == NA check missingness\")). ’re also likely generate false negatives, example == NA appear different lines! Working around issues using un-parsed text every situation amounts re-implementing parser. Therefore recommended work tokens source_file$parsed_content source_file$xml_parsed_content, tokenized R parser. tokens obtained parse() utils::getParseData() calls done prior calling new linter. getParseData() returns data.frame information source parse tree file linted. list tokens available r-source/src/main/gram.y. source_file$xml_parsed_content uses xmlparsedata::xml_parse_data() convert getParseData() output XML tree, enables writing linter logic XPath, powerful language expressing paths within nested XML data structure. linters lintr built using XPath powerful language computation abstract syntax tree / parse tree. , return early source_expression expression-level object. get_source_expression() returns object parses input file two ways – done expression--expression, contains expressions file. done facilitate caching. Suppose package long source file (e.g., 100s expressions) – rather run linters every expression every time file updated, caching activated lintr run linter expressions changed. Therefore, preferable write expression-level linters whenever possible. Two types exceptions observed lintr (1) several expressions required ensure linter logic applies (e.g., conjunct_test_linter looks consecutive calls stopifnot(), typically appear consecutive expressions) (2) linter logic simple & fast compute, overhead re-running linter low (e.g., single_quotes_linter). cases, use is_lint_level(source_expression, \"file\"). source_expression$xml_parsed_content copied local variable (strictly necessary facilitates debugging). xml2::xml_find_all() used execute XPath particular expression. Keep mind typically possible single expression generate one lint – example, x %>% na.omit %>% sum trigger pipe_call_linter() twice3. Finally, pass matching XML node(s) xml_nodes_to_lints(), returns Lint objects corresponding “bad” usages found source_expression. See ?Lint ?xml_nodes_to_lints details arguments. Note , message lint always , many linters, message customized closely match observed usage. cases, xml_nodes_to_lint() can conveniently accept function lint_message takes node input converts customized message. See, example, seq_linter.","code":"#' Pipe call linter #' #' Force explicit calls in magrittr pipes, e.g., #' `1:3 %>% sum()` instead of `1:3 %>% sum`. #' @evalRd rd_tags(\"pipe_call_linter\") #' @seealso [linters] for a complete list of linters available in lintr. #' @export pipe_call_linter <- function() { xpath <- \"//expr[preceding-sibling::SPECIAL[text() = '%>%'] and *[1][self::SYMBOL]]\" //expr # global search (//) for 'expr' nodes (R expressions), at any nesting level [ # node[...] looks for any 'node' satisfying conditions in ... preceding-sibling:: # \"siblings\" are at the same nesting level in XML SPECIAL[ # 'SPECIAL' is the parse token for infix operators like %% or %+% text() = '%>%' # text() returns the string associated with this node ] # and # combine conditions with 'and' * # match any node [1] # match the first such node [self::SYMBOL] # match if the current node is a 'SYMBOL' (i.e., a 'name' in R) ] # Linter(function(source_expression) { if (!is_lint_level(source_expression, \"expression\")) { return(list()) } xml <- source_expression$xml_parsed_content bad_expr <- xml2::xml_find_all(xml, xpath) xml_nodes_to_lints( bad_expr, source_expression = source_expression, lint_message = \"Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`.\", type = \"warning\" )"},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-linter-tests","dir":"Articles","previous_headings":"","what":"Writing linter tests","title":"Creating new linters","text":"(NB: section uses assignment_linter() simpler examples pipe_continuation_linter().) lintr works best inside testthat unit testing framework, particular, lintr exports lintr::expect_lint() designed companion testthat expectations. can define tests inside separate test_that calls. linters use default form. test series expectations linter using expect_lint. Please see ?expect_lint full description parameters. main three aspects test : Linter returns lints nothing lint, e.g. Linter returns lint something lint, e.g. many edge cases can think might break , e.g. may want test additional lint attributes correct, type, line number, column number, e.g. Finally, good idea test linter reports multiple lints needed, e.g. always better write many tests rather .","code":"test_that(\"returns the correct linting\", { expect_lint(\"blah\", NULL, assignment_linter()) expect_lint(\"blah=1\", rex(\"Use <-, not =, for assignment.\"), assignment_linter() ) expect_lint(\"fun((blah = fun(1)))\", rex(\"Use <-, not =, for assignment.\"), assignment_linter() ) expect_lint(\"blah=1\", list(message = \"assignment\", line_number = 1, column_number = 5, type = \"style\"), assignment_linter() ) expect_lint(\"blah=1; blah=2\", list( list(line_number = 1, column_number = 5), list(line_number = 1, column_number = 13), ) assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"other-utilities-for-writing-custom-linters","dir":"Articles","previous_headings":"","what":"Other utilities for writing custom linters","title":"Creating new linters","text":"Besides is_lint_level(), lintr also exports helpers generally useful writing custom linters; used lot internals helpers, ’ve tested demonstrated utility already. get_r_string(): Whenever linter needs examine value character literal (e.g., whether argument value set string), use extract string exactly R see . especially important make logic robust R-4-style raw strings like R\"-(hello)-\", otherwise difficult express, example XPath.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"more-details-about-writing-tests-for-new-lintr-linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"More details about writing tests for new {lintr} linters","title":"Creating new linters","text":"lintr package uses testthat testing. can run currently available tests using devtools::test(). want run tests given file use filter argument devtools::test(). Linter tests put tests/testthat/ folder. test filename linter name prefixed test-, e.g. test-pipe_continuation_linter.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"adding-your-linter-to-the-default_linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Adding your linter to the default_linters","title":"Creating new linters","text":"linter implements part tidyverse style guide can add default_linters. object created file zzz.R (name ensures always run linters defined). Add linter name default_linters list NULL end, add corresponding test case test script ./tests/testthat/default_linter_testcode.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"submit-pull-request","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Submit pull request","title":"Creating new linters","text":"Push changes branch fork lintr repository, submit pull request get linter merged lintr!","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"rstudio","dir":"Articles","previous_headings":"","what":"RStudio","title":"Editor setup","text":"lintr lints automatically displayed RStudio Markers pane (RStudio versions > v0.99.206). RStudio Example order show “Markers” pane RStudio: Menu “Tools” -> “Global Options…”, window title “Options” pop . window: click “Code” left; click “Diagnostics” tab; check “Show diagnostics R”. lint source file test.R type Console lintr::lint(\"test.R\") look result “Markers” pane. package also includes two addins linting current source package. bind addin keyboard shortcut navigate Tools > addins > Browse Addins > Keyboard Shortcuts. ’s recommended use Alt+Shift+L linting current source lint Ctrl+Shift+Alt+L code package. easy remember Alt+Shift+L(int) ;)","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"emacs","dir":"Articles","previous_headings":"","what":"Emacs","title":"Editor setup","text":"lintr built-integration flycheck versions greater 0.23.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation","dir":"Articles","previous_headings":"Emacs","what":"Installation","title":"Editor setup","text":"lintr fully integrated flycheck using ESS. See installation documentation packages information.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration","dir":"Articles","previous_headings":"Emacs","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff. - M-x customize-option -> flycheck-lintr-linters -> linters_with_defaults(line_length_linter(120))","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---syntastic","dir":"Articles","previous_headings":"","what":"Vim - syntastic","title":"Editor setup","text":"lintr can integrated syntastic --fly linting. Vim Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Installation","title":"Editor setup","text":"Put file syntastic/lintr.vim syntastic/syntax_checkers/r. using pathogen directory ~/.vim/bundles/syntastic/syntax_checkers/r. also need add following lines .vimrc.","code":"let g:syntastic_enable_r_lintr_checker = 1 let g:syntastic_r_checkers = ['lintr']"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff.","code":"let g:syntastic_r_lintr_linters = \"linters_with_defaults(line_length_linter(120))\""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---ale","dir":"Articles","previous_headings":"","what":"Vim - ALE","title":"Editor setup","text":"lintr can integrated ALE fly linting.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Installation","title":"Editor setup","text":"lintr integrated ALE requires additional installation.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Configuration","title":"Editor setup","text":"can configure linters used, e.g. using different line length cutoff. can also configure whether lint lint_package used. Set 1 lint_package 0 (default) lint. See :h ale_r_lintr information. Note configuration .lintr files supported. work around can used read contents .lintr file root working directory. allow use configuration .lintr files.","code":"let g:ale_r_lintr_options = \"linters_with_defaults(line_length_linter(120))\" let g:ale_r_lintr_lint_package = 1 if filereadable(\".lintr\") let g:ale_r_lintr_options = join(readfile('.lintr')) endif"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"sublime-text-3","dir":"Articles","previous_headings":"","what":"Sublime Text 3","title":"Editor setup","text":"lintr can integrated Sublime Linter --fly linting. Sublime Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Installation","title":"Editor setup","text":"Simply install sublimeLinter-contrib-lintr using Package Control. information see Sublime Linter Docs","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. disabling assignment linter using different line length cutoff. SublimeLinter User Settings","code":"{ \"linters\": { \"lintr\": { \"linters\": \"linters_with_defaults(assignment_linter = NULL, line_length_linter(120))\" } } }"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"atom","dir":"Articles","previous_headings":"","what":"Atom","title":"Editor setup","text":"lintr can integrated Linter fly linting. Atom Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-4","dir":"Articles","previous_headings":"Atom","what":"Installation","title":"Editor setup","text":"Simply install linter-lintr within Atom command line : information bug reports see Atom linter-lintr.","code":"apm install linter-lintr"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"visual-studio-code","dir":"Articles","previous_headings":"","what":"Visual Studio Code","title":"Editor setup","text":"Visual Studio Code, vscode-R presents lintr diagnostics languageserver. VS Code Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-5","dir":"Articles","previous_headings":"Visual Studio Code","what":"Installation","title":"Editor setup","text":"Installing languageserver package R vscode-R extension VS Code enable lintr VS Code default run following command lines:","code":"Rscript -e 'install.packages(\"languageserver\")' code --install-extension reditorsupport.r"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"running-lintr-on-a-project","dir":"Articles","previous_headings":"","what":"Running lintr on a project","title":"Using lintr","text":"Checking R project lints can done three different functions: Lint single file using lint(): Lint directory using lint_dir(): apply lint() R source files matching pattern argument. default, means .R files well knitr formats (e.g. .Rmd, .Rnw). lint_dir vectorized path, multiple directories can linted time. Lint relevant directories R package using lint_package(): apply lint_dir() subdirectories usually containing R code packages: R containing package implementation. tests containing test code. inst containing sample code vignettes installed along package. vignettes containing package vignettes. data-raw containing code produce data files. information assumed package structure, see R Packages.","code":"lint(filename = \"R/bad.R\") lint_dir(path = \"R\") lint_package(path = \".\")"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"the--lintr-file","dir":"Articles","previous_headings":"Configuring linters","what":"The .lintr file","title":"Using lintr","text":"canonical way configure R projects packages linting create .lintr file project root. file debian control format (?read.dcf), value evaluated R code lintr reading settings. minimal .lintr file can generated running use_lintr() project directory. Lintr supports per-project configuration following fields. linters - see ?linters_with_defaults example specifying non-default linters ?linters_with_tags fine-grained control. exclusions - list filenames exclude linting. can use named item exclude certain lines file. exclude - regex pattern lines exclude linting. Default “# nolint” exclude_start - regex pattern start exclusion range. Default “# nolint start” exclude_end - regex pattern end exclusion range. Default “# nolint end” encoding - encoding used source files. Default inferred .Rproj DESCRIPTION files, fallback UTF-8","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"lintr-file-example","dir":"Articles","previous_headings":"Configuring linters","what":".lintr File Example","title":"Using lintr","text":"example .lintr file uses 120 character line lengths, disables commented_code_linter, excludes couple files.","code":"linters: linters_with_defaults( line_length_linter(120), commented_code_linter = NULL ) exclusions: list( \"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\", \"tests/testthat/exclusions-test\" )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"other-configuration-options","dir":"Articles","previous_headings":"Configuring linters","what":"Other configuration options","title":"Using lintr","text":"generally, lintr searches settings file according following prioritized list. first one found, , used: options(\"lintr.linter_file\") absolute path, file used. default option \".lintr\" value environment variable R_LINTR_LINTER_FILE, set. linter file (, file named like lintr.linter_file) currently-searched directory, .e. directory file passed lint(); linter file .github/linters child directory currently-searched directory. project-local linter file closest parent directory currently-searched directory, starting deepest path, moving upwards one level time. run lint_package(), directory can differ linted file. linter file user’s HOME directory. linter file called config user’s configuration path (given tools::R_user_dir(\"lintr\", = \"config\")). linter file found, default settings take effect (see defaults).","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-options","dir":"Articles","previous_headings":"Configuring linters","what":"Using options()","title":"Using lintr","text":"Values options(), NULL, take precedence linter file (e.g. .lintr). Note key option_name linter file translates R option lintr.option_name. example, options(lintr.exclude = \"# skip lint\") take precedence exclude: # nolint linter file.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-arguments-to-lint","dir":"Articles","previous_headings":"Configuring linters","what":"Using arguments to lint()","title":"Using lintr","text":"settings can also passed arguments linting functions directly. case exclusions, combined globally parsed settings. settings overridden. specified settings changed, remaining settings taken directly defaults, argument parse_settings = FALSE can added function calls. suppress reading .lintr configuration. particularly useful tests exclude example files containing lints package-level .lintr excludes files lints intentional.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"defaults","dir":"Articles","previous_headings":"Configuring linters","what":"Defaults","title":"Using lintr","text":"default settings lintr intended conform tidyverse style guide. However, behavior can customized using different methods. Apart lintr.linter_file, defaults \".lintr\", following settings: Note default encoding setting depends file linted. Encoding found .Rproj file DESCRIPTION file, encoding overrides default UTF-8.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"customizing-active-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Customizing active linters","title":"Using lintr","text":"want customize linters, can use helper function linters_with_defaults(), keep unnamed linters default settings. Disable linter passing NULL. example, set line length limit 120 characters globally disable whitespace_linter(), can put .lintr: default, following linters enabled. applicable, default settings also shown. Another way customize linters specifying tags linters_with_tags(). available tags listed : can select tags interest see linters included: can include tag-based linters configuration file, customize :","code":"linters: linters_with_defaults( line_length_linter = line_length_linter(120L), whitespace_linter = NULL ) lintr::available_tags(packages = \"lintr\") #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"readability\" \"robustness\" #> [13] \"style\" linters <- lintr::linters_with_tags(tags = c(\"package_development\", \"readability\")) names(linters) #> [1] \"backport_linter\" \"boolean_arithmetic_linter\" #> [3] \"brace_linter\" \"commas_linter\" #> [5] \"commented_code_linter\" \"conjunct_test_linter\" #> [7] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [9] \"empty_assignment_linter\" \"expect_comparison_linter\" #> [11] \"expect_identical_linter\" \"expect_length_linter\" #> [13] \"expect_named_linter\" \"expect_not_linter\" #> [15] \"expect_null_linter\" \"expect_s3_class_linter\" #> [17] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [19] \"expect_type_linter\" \"fixed_regex_linter\" #> [21] \"for_loop_index_linter\" \"function_left_parentheses_linter\" #> [23] \"function_return_linter\" \"implicit_assignment_linter\" #> [25] \"indentation_linter\" \"infix_spaces_linter\" #> [27] \"inner_combine_linter\" \"is_numeric_linter\" #> [29] \"lengths_linter\" \"line_length_linter\" #> [31] \"matrix_apply_linter\" \"nested_ifelse_linter\" #> [33] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [35] \"object_usage_linter\" \"outer_negation_linter\" #> [37] \"package_hooks_linter\" \"paren_body_linter\" #> [39] \"pipe_call_linter\" \"pipe_continuation_linter\" #> [41] \"quotes_linter\" \"redundant_equals_linter\" #> [43] \"semicolon_linter\" \"sort_linter\" #> [45] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [47] \"string_boundary_linter\" \"system_file_linter\" #> [49] \"T_and_F_symbol_linter\" \"unnecessary_concatenation_linter\" #> [51] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [53] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [55] \"yoda_test_linter\" linters: linters_with_tags( tags = c(\"package_development\", \"readability\"), yoda_test_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-all-available-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Using all available linters","title":"Using lintr","text":"default lintr configuration includes linters relevant tidyverse style guide, many linters available lintr. can see list available linters using want use available linters, can include .lintr file: want use available linters except , can exclude using NULL:","code":"names(lintr::all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"condition_message_linter\" \"conjunct_test_linter\" #> [13] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [15] \"duplicate_argument_linter\" \"empty_assignment_linter\" #> [17] \"equals_na_linter\" \"expect_comparison_linter\" #> [19] \"expect_identical_linter\" \"expect_length_linter\" #> [21] \"expect_named_linter\" \"expect_not_linter\" #> [23] \"expect_null_linter\" \"expect_s3_class_linter\" #> [25] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [27] \"expect_type_linter\" \"extraction_operator_linter\" #> [29] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [31] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [33] \"function_return_linter\" \"ifelse_censor_linter\" #> [35] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [37] \"indentation_linter\" \"infix_spaces_linter\" #> [39] \"inner_combine_linter\" \"is_numeric_linter\" #> [41] \"lengths_linter\" \"line_length_linter\" #> [43] \"literal_coercion_linter\" \"matrix_apply_linter\" #> [45] \"missing_argument_linter\" \"missing_package_linter\" #> [47] \"namespace_linter\" \"nested_ifelse_linter\" #> [49] \"nonportable_path_linter\" \"numeric_leading_zero_linter\" #> [51] \"object_length_linter\" \"object_name_linter\" #> [53] \"object_usage_linter\" \"outer_negation_linter\" #> [55] \"package_hooks_linter\" \"paren_body_linter\" #> [57] \"paste_linter\" \"pipe_call_linter\" #> [59] \"pipe_continuation_linter\" \"quotes_linter\" #> [61] \"redundant_equals_linter\" \"redundant_ifelse_linter\" #> [63] \"regex_subset_linter\" \"routine_registration_linter\" #> [65] \"semicolon_linter\" \"seq_linter\" #> [67] \"sort_linter\" \"spaces_inside_linter\" #> [69] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [71] \"string_boundary_linter\" \"strings_as_factors_linter\" #> [73] \"system_file_linter\" \"T_and_F_symbol_linter\" #> [75] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [77] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [79] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [81] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [83] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [85] \"unused_import_linter\" \"vector_logic_linter\" #> [87] \"whitespace_linter\" \"yoda_test_linter\" linters: all_linters() linters: all_linters( commented_code_linter = NULL, implicit_integer_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"advanced-programmatic-retrieval-of-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Advanced: programmatic retrieval of linters","title":"Using lintr","text":"use cases, may useful specify linters string instead name, .e. \"assignment_linter\" instead writing assignment_linter(). Beware cases, simple get() enough:","code":"library(lintr) #> #> Attaching package: 'lintr' #> The following object is masked _by_ '.GlobalEnv': #> #> default_settings linter_name <- \"assignment_linter\" withr::with_tempfile(\"tmp\", { writeLines(\"a = 1\", tmp) # linter column is just 'get' print(as.data.frame(lint(tmp, linters = get(linter_name)()))) this_linter <- get(linter_name)() attr(this_linter, \"name\") <- linter_name # linter column is 'assignment_linter' print(as.data.frame(lint(tmp, linters = this_linter))) # more concise alternative: use eval(call(.)) print(as.data.frame(lint(tmp, linters = eval(call(linter_name))))) }) #> filename line_number column_number type #> 1 /tmp/Rtmpq44p2b/file1e092fe2520c 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 get #> filename line_number column_number type #> 1 /tmp/Rtmpq44p2b/file1e092fe2520c 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter #> filename line_number column_number type #> 1 /tmp/Rtmpq44p2b/file1e092fe2520c 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"exclusions","dir":"Articles","previous_headings":"","what":"Exclusions","title":"Using lintr","text":"Sometimes, linters globally disabled. Instead, one might want exclude code linting altogether selectively disable linters part code. Note preferred way excluding lints source code use narrowest possible scope specify exactly linters throw lint marked line. prevents accidental suppression justified lints happen line lint needs suppressed.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-of-code","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines of code","title":"Using lintr","text":"Within source files, special comments can used exclude single lines code linting. lints produced marked line excluded results. default, special comment # nolint: file.R > lint(\"file.R\") file2.R > lint(\"file2.R\") Observe lints suppressed output shown. Sometimes, specific linter needs excluded. case, name linter can appended # nolint comment preceded colon terminated dot.","code":"X = 42L # -------------- this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. X = 42L # nolint ------ this comment overflows the default 80 chars line length."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-only-some-linters","dir":"Articles","previous_headings":"Exclusions","what":"Excluding only some linters","title":"Using lintr","text":"file3.R > lint(\"file3.R\") Observe object_name_linter suppressed. preferable blanket # nolint statements blanket exclusions may accidentally silence linter intentionally suppressed. Multiple linters can specified listing comma separator: file4.R > lint(\"file4.R\") can also specify linter names unique prefix instead full name: file5.R > lint(\"file5.R\")","code":"X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-multiple-lines-of-codes","dir":"Articles","previous_headings":"Exclusions","what":"Excluding multiple lines of codes","title":"Using lintr","text":"linters disabled contiguous block code, exclude_start exclude_end patterns can used. default # nolint start # nolint end respectively. # nolint start accepts syntax # nolint disable specific linters following lines # nolint end encountered. (lints)","code":"# x <- 42L # print(x) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Commented code should be removed. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[commented_code_linter] Commented code should be removed. # nolint start: commented_code_linter. # x <- 42L # print(x) # nolint end"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-via-the-config-file","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines via the config file","title":"Using lintr","text":"Individual lines can also excluded via config file setting key exclusions list elements corresponding different files. exclude lints line 1 file R/bad.R line_length_linter lines 4 6 file, one can set paths interpreted relative location .lintr file.","code":"exclusions: list( \"R/bad.R\" = list( 1, # global exclusions are unnamed line_length_linter = 4:6 ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-files-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding files completely","title":"Using lintr","text":"linter configuration can also used exclude file entirely, linter file entirely. Use sentinel line number Inf mark lines excluded within file. file given character vector, full exclusion implied.","code":"exclusions: list( # excluded from all lints: \"R/excluded1.R\", \"R/excluded2.R\" = Inf, \"R/excluded3.R\" = list(Inf), # excluded from line_length_linter: \"R/no-line-length.R\" = list( line_length_linter = Inf ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-directories-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding directories completely","title":"Using lintr","text":"Entire directories also recognized supplied strings exclusions key. example, exclude renv folder linting R project using renv, set particularly useful projects include external code subdirectories.","code":"exclusions: list( \"renv\" )"},{"path":"https://lintr.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Jim Hester. Author, maintainer. Florent Angly. Author. fangly Russ Hyde. Author. Michael Chirico. Author. Kun Ren. Author. Alexander Rosenstock. Author. AshesITR Indrajeet Patil. Author. @patilindrajeets","code":""},{"path":"https://lintr.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hester J, Angly F, Hyde R, Chirico M, Ren K, Rosenstock , Patil (2023). lintr: 'Linter' R Code. https://github.com/r-lib/lintr, https://lintr.r-lib.org.","code":"@Manual{, title = {lintr: A 'Linter' for R Code}, author = {Jim Hester and Florent Angly and Russ Hyde and Michael Chirico and Kun Ren and Alexander Rosenstock and Indrajeet Patil}, year = {2023}, note = {https://github.com/r-lib/lintr, https://lintr.r-lib.org}, }"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"lintr","dir":"","previous_headings":"","what":"A Linter for R Code","title":"A Linter for R Code","text":"lintr provides static code analysis R. checks adherence given style, identifying syntax errors possible semantic issues, reports can take action. Watch lintr action following animation: lintr complementary {styler} package automatically restyles code, eliminating problems lintr can detect.","code":""},{"path":"https://lintr.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"A Linter for R Code","text":"Install stable version CRAN: development version GitHub:","code":"install.packages(\"lintr\") # install.packages(\"remotes\") remotes::install_github(\"r-lib/lintr\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"A Linter for R Code","text":"can create configuration file run selected linters: see list linters included configuration:","code":"lintr::use_lintr(type = \"tidyverse\") # in a project: lintr::lint_dir() # in a package: lintr::lint_package() # tidyverse (default) names(lintr::linters_with_defaults()) # full names(lintr::all_linters())"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"setting-up-github-actions","dir":"","previous_headings":"Usage","what":"Setting up GitHub Actions","title":"A Linter for R Code","text":"usethis provides helper functions generate lint workflows GitHub Actions: can also run lintr continuous integration within IDE text editor. See vignette(\"continuous-integration\") vignette(\"editors\") details. Without configuration, run default linters. See vignette(\"lintr\") learn modify defaults.","code":"# in a project: usethis::use_github_action(\"lint-project\") # in a package: usethis::use_github_action(\"lint\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"A Linter for R Code","text":"Please note lintr project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter closure — Linter","title":"Create a linter closure — Linter","text":"Create linter closure","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter closure — Linter","text":"","code":"Linter(fun, name = linter_auto_name())"},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter closure — Linter","text":"fun function takes source file returns lint objects. name Default name Linter. Lints produced linter labelled name default.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a linter closure — Linter","text":"function class set 'linter'.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"T and F symbol linter — T_and_F_symbol_linter","title":"T and F symbol linter — T_and_F_symbol_linter","text":"Avoid symbols T F, use TRUE FALSE instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"T_and_F_symbol_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"T and F symbol linter — T_and_F_symbol_linter","text":"best_practices, consistency, default, readability, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"# will produce lints lint( text = \"x <- T; y <- F\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[T_and_F_symbol_linter] Use TRUE instead of the symbol T. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[T_and_F_symbol_linter] Use FALSE instead of the symbol F. lint( text = \"T = 1.2; F = 2.4\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[T_and_F_symbol_linter] Don't use T as a variable name, as it can break code relying on T being TRUE. #> ::warning file=,line=1,col=11::file=,line=1,col=11,[T_and_F_symbol_linter] Don't use F as a variable name, as it can break code relying on F being FALSE. # okay lint( text = \"x <- c(TRUE, FALSE)\", linters = T_and_F_symbol_linter() ) lint( text = \"t = 1.2; f = 2.4\", linters = T_and_F_symbol_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Absolute path linter — absolute_path_linter","title":"Absolute path linter — absolute_path_linter","text":"Check absolute paths used (e.g. \"/var\", \"C:\\System\", \"~/docs\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Absolute path linter — absolute_path_linter","text":"","code":"absolute_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Absolute path linter — absolute_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Absolute path linter — absolute_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Absolute path linter — absolute_path_linter","text":"","code":"# Following examples use raw character constant syntax introduced in R 4.0. # will produce lints lint( text = 'R\"--[/blah/file.txt]--\"', linters = absolute_path_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[absolute_path_linter] Do not use absolute paths. # okay lint( text = 'R\"(./blah)\"', linters = absolute_path_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on all available linters — all_linters","title":"Create a linter configuration based on all available linters — all_linters","text":"Create linter configuration based available linters","code":""},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"all_linters(packages = \"lintr\", ...)"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on all available linters — all_linters","text":"packages character vector packages search linters. ... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"names(all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"condition_message_linter\" \"conjunct_test_linter\" #> [13] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [15] \"duplicate_argument_linter\" \"empty_assignment_linter\" #> [17] \"equals_na_linter\" \"expect_comparison_linter\" #> [19] \"expect_identical_linter\" \"expect_length_linter\" #> [21] \"expect_named_linter\" \"expect_not_linter\" #> [23] \"expect_null_linter\" \"expect_s3_class_linter\" #> [25] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [27] \"expect_type_linter\" \"extraction_operator_linter\" #> [29] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [31] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [33] \"function_return_linter\" \"ifelse_censor_linter\" #> [35] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [37] \"indentation_linter\" \"infix_spaces_linter\" #> [39] \"inner_combine_linter\" \"is_numeric_linter\" #> [41] \"lengths_linter\" \"line_length_linter\" #> [43] \"literal_coercion_linter\" \"matrix_apply_linter\" #> [45] \"missing_argument_linter\" \"missing_package_linter\" #> [47] \"namespace_linter\" \"nested_ifelse_linter\" #> [49] \"nonportable_path_linter\" \"numeric_leading_zero_linter\" #> [51] \"object_length_linter\" \"object_name_linter\" #> [53] \"object_usage_linter\" \"outer_negation_linter\" #> [55] \"package_hooks_linter\" \"paren_body_linter\" #> [57] \"paste_linter\" \"pipe_call_linter\" #> [59] \"pipe_continuation_linter\" \"quotes_linter\" #> [61] \"redundant_equals_linter\" \"redundant_ifelse_linter\" #> [63] \"regex_subset_linter\" \"routine_registration_linter\" #> [65] \"semicolon_linter\" \"seq_linter\" #> [67] \"sort_linter\" \"spaces_inside_linter\" #> [69] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [71] \"string_boundary_linter\" \"strings_as_factors_linter\" #> [73] \"system_file_linter\" \"T_and_F_symbol_linter\" #> [75] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [77] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [79] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [81] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [83] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [85] \"unused_import_linter\" \"vector_logic_linter\" #> [87] \"whitespace_linter\" \"yoda_test_linter\""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"anyDuplicated() exists replacement (duplicated(.)), efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"any_duplicated_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"Also match usage like length(unique(x$col)) == nrow(x), can replaced anyDuplicated(x$col) == 0L.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"# will produce lints lint( text = \"any(duplicated(x), na.rm = TRUE)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). lint( text = \"length(unique(x)) == length(x)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). # okay lint( text = \"anyDuplicated(x)\", linters = any_duplicated_linter() ) lint( text = \"anyDuplicated(x) == 0L\", linters = any_duplicated_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"anyNA() exists replacement (.na(x)) efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"any_is_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"# will produce lints lint( text = \"any(is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). lint( text = \"any(is.na(foo(x)))\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). # okay lint( text = \"anyNA(x)\", linters = any_is_na_linter() ) lint( text = \"anyNA(foo(x))\", linters = any_is_na_linter() ) lint( text = \"any(!is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Assignment linter — assignment_linter","title":"Assignment linter — assignment_linter","text":"Check <- always used assignment.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assignment linter — assignment_linter","text":"","code":"assignment_linter( allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE, allow_pipe_assign = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Assignment linter — assignment_linter","text":"allow_cascading_assign Logical, default TRUE. FALSE, <<- ->> allowed. allow_right_assign Logical, default FALSE. TRUE, -> ->> allowed. allow_trailing Logical, default TRUE. FALSE assignments allowed end lines. allow_pipe_assign Logical, default FALSE. TRUE, magrittr's %<>% assignment allowed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Assignment linter — assignment_linter","text":"configurable, consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Assignment linter — assignment_linter","text":"","code":"# will produce lints lint( text = \"x = mean(x)\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not ->, for assignment. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[assignment_linter] ->> can have hard-to-predict behavior; prefer assigning to a specific environment instead (with assign() or <-). lint( text = \"x %<>% as.character()\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Avoid the assignment pipe %<>%; prefer using <- and %>% separately. # okay lint( text = \"x <- mean(x)\", linters = assignment_linter() ) code_lines <- \"x <- 1\\ny <<- 2\" writeLines(code_lines) #> x <- 1 #> y <<- 2 lint( text = code_lines, linters = assignment_linter() ) # customizing using arguments code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter(allow_right_assign = TRUE) ) lint( text = \"x <<- 1\", linters = assignment_linter(allow_cascading_assign = FALSE) ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] <<- can have hard-to-predict behavior; prefer assigning to a specific environment instead (with assign() or <-). writeLines(\"foo(bar = \\n 1)\") #> foo(bar = #> 1) lint( text = \"foo(bar = \\n 1)\", linters = assignment_linter(allow_trailing = FALSE) ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[assignment_linter] Assignment = should not be trailing at the end of a line. lint( text = \"x %<>% as.character()\", linters = assignment_linter(allow_pipe_assign = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Linter metadata from a package — available_linters","title":"Get Linter metadata from a package — available_linters","text":"available_linters() obtains tagged list Linters available package. available_tags() searches available tags.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Linter metadata from a package — available_linters","text":"","code":"available_linters(packages = \"lintr\", tags = NULL, exclude_tags = \"deprecated\") available_tags(packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Linter metadata from a package — available_linters","text":"packages character vector packages search linters. tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. exclude_tags Tags exclude results. Linters least one matching tag returned. except_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get Linter metadata from a package — available_linters","text":"available_linters returns data frame columns 'linter', 'package' 'tags': linter character column naming function associated linter. package character column containing name package providing linter. tags list column containing tags associated linter. available_tags returns character vector linter tags used packages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"package-authors","dir":"Reference","previous_headings":"","what":"Package Authors","title":"Get Linter metadata from a package — available_linters","text":"implement available_linters() package, include file inst/lintr/linters.csv package. CSV file must contain columns 'linter' 'tags', UTF-8 encoded. Additional columns silently ignored present columns identified name. row describes linter function name (e.g. \"assignment_linter\") column 'linter'. space-separated tags associated linter (e.g. \"style consistency default\") column 'tags'. Tags snake_case. See available_tags(\"lintr\") find tags already used lintr.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get Linter metadata from a package — available_linters","text":"","code":"lintr_linters <- available_linters() # If the package doesn't exist or isn't installed, an empty data frame will be returned available_linters(\"does-not-exist\") #> [1] linter package tags #> <0 rows> (or 0-length row.names) lintr_linters2 <- available_linters(c(\"lintr\", \"does-not-exist\")) identical(lintr_linters, lintr_linters2) #> [1] TRUE available_tags() #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"readability\" \"robustness\" #> [13] \"style\""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Backport linter — backport_linter","title":"Backport linter — backport_linter","text":"Check usage unavailable functions. reliable testing r-devel dependencies.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Backport linter — backport_linter","text":"","code":"backport_linter(r_version = getRversion(), except = character())"},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Backport linter — backport_linter","text":"r_version Minimum R version test compatibility except Character vector functions excluded linting. Use list explicitly defined backports, e.g. imported backports package manually defined package.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Backport linter — backport_linter","text":"configurable, package_development, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Backport linter — backport_linter","text":"","code":"# will produce lints lint( text = \"trimws(x)\", linters = backport_linter(\"3.0.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] trimws (R 3.2.0) is not available for dependency R >= 3.0.0. Use the `except` argument of `backport_linter()` to configure available backports. lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] str2lang (R 3.6.0) is not available for dependency R >= 3.2.0. Use the `except` argument of `backport_linter()` to configure available backports. # okay lint( text = \"trimws(x)\", linters = backport_linter(\"3.6.0\") ) lint( text = \"str2lang(x)\", linters = backport_linter(\"4.0.0\") )"},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Best practices linters — best_practices_linters","title":"Best practices linters — best_practices_linters","text":"Linters checking use coding best practices, explicit typing numeric constants.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Best practices linters — best_practices_linters","text":"following linters tagged 'best_practices': absolute_path_linter any_duplicated_linter any_is_na_linter boolean_arithmetic_linter class_equals_linter commented_code_linter condition_message_linter conjunct_test_linter cyclocomp_linter empty_assignment_linter expect_comparison_linter expect_length_linter expect_named_linter expect_not_linter expect_null_linter expect_s3_class_linter expect_s4_class_linter expect_true_false_linter expect_type_linter extraction_operator_linter fixed_regex_linter for_loop_index_linter function_argument_linter function_return_linter ifelse_censor_linter implicit_assignment_linter implicit_integer_linter is_numeric_linter lengths_linter literal_coercion_linter nonportable_path_linter outer_negation_linter paste_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter seq_linter sort_linter system_file_linter T_and_F_symbol_linter undesirable_function_linter undesirable_operator_linter unnecessary_lambda_linter unnecessary_nested_if_linter unnecessary_placeholder_linter unreachable_code_linter unused_import_linter vector_logic_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"length((x == y)) == 0 !(x == y), latter readable efficient.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"boolean_arithmetic_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"# will produce lints lint( text = \"length(which(x == y)) == 0L\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). lint( text = \"sum(grepl(pattern, x)) == 0\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). # okay lint( text = \"!any(x == y)\", linters = boolean_arithmetic_linter() ) lint( text = \"!any(grepl(pattern, x))\", linters = boolean_arithmetic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Brace linter — brace_linter","title":"Brace linter — brace_linter","text":"Perform various style checks related placement spacing curly braces:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Brace linter — brace_linter","text":"","code":"brace_linter(allow_single_line = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Brace linter — brace_linter","text":"allow_single_line TRUE, allow open closed curly pair line.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Brace linter — brace_linter","text":"Opening curly braces never line always followed newline. Opening curly braces space . Closing curly braces line unless followed else. Closing curly braces conditions line corresponding else. Either neither branch /else use curly braces, .e., either branches use {...} neither . Functions spanning multiple lines use curly braces.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Brace linter — brace_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Brace linter — brace_linter","text":"","code":"# will produce lints lint( text = \"f <- function() { 1 }\", linters = brace_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line. #> ::warning file=,line=1,col=21::file=,line=1,col=21,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. writeLines(\"if (TRUE) {\\n return(1) }\") #> if (TRUE) { #> return(1) } lint( text = \"if (TRUE) {\\n return(1) }\", linters = brace_linter() ) #> ::warning file=,line=2,col=12::file=,line=2,col=12,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. # okay writeLines(\"f <- function() {\\n 1\\n}\") #> f <- function() { #> 1 #> } lint( text = \"f <- function() {\\n 1\\n}\", linters = brace_linter() ) writeLines(\"if (TRUE) { \\n return(1) \\n}\") #> if (TRUE) { #> return(1) #> } lint( text = \"if (TRUE) { \\n return(1) \\n}\", linters = brace_linter() ) # customizing using arguments writeLines(\"if (TRUE) { return(1) }\") #> if (TRUE) { return(1) } lint( text = \"if (TRUE) { return(1) }\", linters = brace_linter(allow_single_line = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Checkstyle Report for lint results — checkstyle_output","title":"Checkstyle Report for lint results — checkstyle_output","text":"Generate report linting results using Checkstyle XML format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Checkstyle Report for lint results — checkstyle_output","text":"","code":"checkstyle_output(lints, filename = \"lintr_results.xml\")"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Checkstyle Report for lint results — checkstyle_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block comparison of class with == — class_equals_linter","title":"Block comparison of class with == — class_equals_linter","text":"Usage like class(x) == \"character\" prone error since class R general vector. correct version S3 classes inherits(): inherits(x, \"character\"). Often, class k . equivalent, example .character() .data.frame().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block comparison of class with == — class_equals_linter","text":"","code":"class_equals_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block comparison of class with == — class_equals_linter","text":"Similar reasoning applies class(x) %% \"character\".","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block comparison of class with == — class_equals_linter","text":"best_practices, consistency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block comparison of class with == — class_equals_linter","text":"","code":"# will produce lints lint( text = 'is_lm <- class(x) == \"lm\"', linters = class_equals_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[class_equals_linter] Instead of comparing class(x) with ==, use inherits(x, 'class-name') or is. or is(x, 'class') lint( text = 'if (\"lm\" %in% class(x)) is_lm <- TRUE', linters = class_equals_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[class_equals_linter] Instead of comparing class(x) with %in%, use inherits(x, 'class-name') or is. or is(x, 'class') # okay lint( text = 'is_lm <- inherits(x, \"lm\")', linters = class_equals_linter() ) lint( text = 'if (inherits(x, \"lm\")) is_lm <- TRUE', linters = class_equals_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":null,"dir":"Reference","previous_headings":"","what":"Clear the lintr cache — clear_cache","title":"Clear the lintr cache — clear_cache","text":"Clear lintr cache","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Clear the lintr cache — clear_cache","text":"","code":"clear_cache(file = NULL, path = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Clear the lintr cache — clear_cache","text":"file filename whose cache clear. pass NULL, delete caches. path directory store caches. Reads option 'lintr.cache_directory' default.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Clear the lintr cache — clear_cache","text":"0 success, 1 failure, invisibly.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commas linter — commas_linter","title":"Commas linter — commas_linter","text":"Check commas followed spaces, spaces .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commas linter — commas_linter","text":"","code":"commas_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commas linter — commas_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commas linter — commas_linter","text":"","code":"# will produce lints lint( text = \"switch(op , x = foo, y = bar)\", linters = commas_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[commas_linter] Commas should never have a space before. lint( text = \"mean(x,trim = 0.2,na.rm = TRUE)\", linters = commas_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[commas_linter] Commas should always have a space after. #> ::warning file=,line=1,col=19::file=,line=1,col=19,[commas_linter] Commas should always have a space after. lint( text = \"x[ ,, drop=TRUE]\", linters = commas_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commas_linter] Commas should never have a space before. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Commas should always have a space after. # okay lint( text = \"switch(op, x = foo, y = bar)\", linters = commas_linter() ) lint( text = \"switch(op, x = , y = bar)\", linters = commas_linter() ) lint( text = \"mean(x, trim = 0.2, na.rm = TRUE)\", linters = commas_linter() ) lint( text = \"a[1, , 2, , 3]\", linters = commas_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commented code linter — commented_code_linter","title":"Commented code linter — commented_code_linter","text":"Check commented code outside roxygen blocks.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commented code linter — commented_code_linter","text":"","code":"commented_code_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commented code linter — commented_code_linter","text":"best_practices, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commented code linter — commented_code_linter","text":"","code":"# will produce lints lint( text = \"# x <- 1\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Commented code should be removed. lint( text = \"x <- f() # g()\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[commented_code_linter] Commented code should be removed. lint( text = \"x + y # + z[1, 2]\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[commented_code_linter] Commented code should be removed. # okay lint( text = \"x <- 1; x <- f(); x + y\", linters = commented_code_linter() ) lint( text = \"#' x <- 1\", linters = commented_code_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Common mistake linters — common_mistakes_linters","title":"Common mistake linters — common_mistakes_linters","text":"Linters highlighting common mistakes, duplicate arguments.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Common mistake linters — common_mistakes_linters","text":"following linters tagged 'common_mistakes': duplicate_argument_linter equals_na_linter missing_argument_linter missing_package_linter redundant_equals_linter sprintf_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"linter discourages combining condition functions like stop() string concatenation functions paste() paste0(). ","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"condition_message_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"stop(paste0(...)) redundant exactly equivalent stop(...) stop(paste(...)) similarly equivalent stop(...) separators (see examples) applies default condition functions well, .e., warning(), message(), packageStartupMessage().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"best_practices, consistency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"# will produce lints lint( text = 'stop(paste(\"a string\", \"another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste to build stop strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). lint( text = 'warning(paste0(\"a string\", \" another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste0 to build warning strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). # okay lint( text = 'stop(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(paste(\"a string\", \"another\", sep = \"-\"))', linters = condition_message_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Configurable linters — configurable_linters","title":"Configurable linters — configurable_linters","text":"Generic linters support custom configuration needs.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Configurable linters — configurable_linters","text":"following linters tagged 'configurable': absolute_path_linter assignment_linter backport_linter brace_linter conjunct_test_linter cyclocomp_linter duplicate_argument_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter line_length_linter missing_argument_linter namespace_linter nonportable_path_linter object_length_linter object_name_linter object_usage_linter paste_linter quotes_linter redundant_ifelse_linter semicolon_linter string_boundary_linter todo_comment_linter trailing_whitespace_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"readability test outputs, testing one thing per call testthat::expect_true() preferable, .e., expect_true(); expect_true(B) better expect_true(&& B), expect_false(); expect_false(B) better expect_false(|| B).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"","code":"conjunct_test_linter(allow_named_stopifnot = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"allow_named_stopifnot Logical, TRUE default. FALSE, \"named\" calls stopifnot(), available since R 4.0.0 provide helpful messages test failures, also linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"Similar reasoning applies && usage inside stopifnot() assertthat::assert_that() calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"best_practices, configurable, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x && y)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of expect_true(A && B), write multiple expectations like expect_true(A) and expect_true(B) The latter will produce better error messages in the case of failure. lint( text = \"expect_false(x || (y && z))\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of expect_false(A || B), write multiple expectations like expect_false(A) and expect_false(B) The latter will produce better error messages in the case of failure. lint( text = \"stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))\", linters = conjunct_test_linter(allow_named_stopifnot = FALSE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of stopifnot(A && B), write multiple conditions like stopifnot(A, B). The latter will produce better error messages in the case of failure. # okay lint( text = \"expect_true(x || (y && z))\", linters = conjunct_test_linter() ) lint( text = 'stopifnot(\"x must be a logical scalar\" = length(x) == 1 && is.logical(x) && !is.na(x))', linters = conjunct_test_linter(allow_named_stopifnot = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"stopifnot() accepts number tests, sequences like stopifnot(x); stopifnot(y) redundant. Ditto tests using assertthat::assert_that() without specifying msg=.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"consecutive_assertion_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"# will produce lints lint( text = \"stopifnot(x); stopifnot(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to stopifnot(). lint( text = \"assert_that(x); assert_that(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to assert_that(). # okay lint( text = \"stopifnot(x, y)\", linters = consecutive_assertion_linter() ) lint( text = 'assert_that(x, msg = \"Bad x!\"); assert_that(y)', linters = consecutive_assertion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Consistency linters — consistency_linters","title":"Consistency linters — consistency_linters","text":"Linters checking enforcing consistent alternative multiple syntactically valid ways write something.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Consistency linters — consistency_linters","text":"following linters tagged 'consistency': assignment_linter class_equals_linter condition_message_linter consecutive_assertion_linter function_argument_linter implicit_integer_linter inner_combine_linter is_numeric_linter literal_coercion_linter numeric_leading_zero_linter object_name_linter paste_linter quotes_linter redundant_ifelse_linter seq_linter system_file_linter T_and_F_symbol_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Correctness linters — correctness_linters","title":"Correctness linters — correctness_linters","text":"Linters highlighting possible programming mistakes, unused variables.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Correctness linters — correctness_linters","text":"following linters tagged 'correctness': duplicate_argument_linter equals_na_linter missing_argument_linter namespace_linter object_usage_linter package_hooks_linter sprintf_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Cyclomatic complexity linter — cyclocomp_linter","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"Check overly complicated expressions. See cyclocomp::cyclocomp().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"cyclocomp_linter(complexity_limit = 15L)"},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"complexity_limit Maximum cyclomatic complexity, default 15. Expressions complex linted. See cyclocomp::cyclocomp().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"best_practices, configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"# will produce lints lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 1L) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[cyclocomp_linter] Functions should have cyclomatic complexity of less than 1, this has 2. # okay lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 2L) )"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Default linters — default_linters","title":"Default linters — default_linters","text":"List default linters lint(). Use linters_with_defaults() customize . default linters based tidyverse style guide. set default linters follows (parameterized linters, e.g., line_length_linter use default argument(s), see ? details):","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default linters — default_linters","text":"","code":"default_linters"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default linters — default_linters","text":"object class list length 25.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Default linters — default_linters","text":"following linters tagged 'default': assignment_linter brace_linter commas_linter commented_code_linter cyclocomp_linter equals_na_linter function_left_parentheses_linter indentation_linter infix_spaces_linter line_length_linter object_length_linter object_name_linter object_usage_linter paren_body_linter pipe_continuation_linter quotes_linter semicolon_linter seq_linter spaces_inside_linter spaces_left_parentheses_linter T_and_F_symbol_linter trailing_blank_lines_linter trailing_whitespace_linter vector_logic_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":null,"dir":"Reference","previous_headings":"","what":"Default lintr settings — default_settings","title":"Default lintr settings — default_settings","text":"default settings consist linters: list default linters (see default_linters()) encoding: character encoding assumed file exclude: pattern used exclude line code exclude_start, exclude_end: patterns used mark start end code block exclude exclude_linter, exclude_linter_sep: patterns used exclude linters exclusions:list files exclude cache_directory: location cache directory comment_token: GitHub token character comment_bot: decides lintr comment bot GitHub can comment commits error_on_lint: decides error produced lints found","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default lintr settings — default_settings","text":"","code":"default_settings"},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default lintr settings — default_settings","text":"object class list length 12.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Default lintr settings — default_settings","text":"","code":"# available settings names(default_settings) #> [1] \"linters\" \"encoding\" \"exclude\" #> [4] \"exclude_start\" \"exclude_end\" \"exclude_linter\" #> [7] \"exclude_linter_sep\" \"exclusions\" \"cache_directory\" #> [10] \"comment_token\" \"comment_bot\" \"error_on_lint\" # linters included by default names(default_settings$linters) #> [1] \"assignment_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"cyclocomp_linter\" \"equals_na_linter\" #> [7] \"function_left_parentheses_linter\" \"indentation_linter\" #> [9] \"infix_spaces_linter\" \"line_length_linter\" #> [11] \"object_length_linter\" \"object_name_linter\" #> [13] \"object_usage_linter\" \"paren_body_linter\" #> [15] \"pipe_continuation_linter\" \"quotes_linter\" #> [17] \"semicolon_linter\" \"seq_linter\" #> [19] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [21] \"T_and_F_symbol_linter\" \"trailing_blank_lines_linter\" #> [23] \"trailing_whitespace_linter\" \"vector_logic_linter\" #> [25] \"whitespace_linter\" # default values for a few of the other settings default_settings[c( \"encoding\", \"exclude\", \"exclude_start\", \"exclude_end\", \"exclude_linter\", \"exclude_linter_sep\", \"exclusions\", \"error_on_lint\" )] #> $encoding #> [1] \"UTF-8\" #> #> $exclude #> #[[:space:]]*nolint #> #> $exclude_start #> #[[:space:]]*nolint start #> #> $exclude_end #> #[[:space:]]*nolint end #> #> $exclude_linter #> ^[[:space:]]*:[[:space:]]*(?(?:(?:[^,.])+[[:space:]]*,[[:space:]]*)*(?:[^,.])+)\\. #> #> $exclude_linter_sep #> [[:space:]]*,[[:space:]]* #> #> $exclusions #> list() #> #> $error_on_lint #> [1] FALSE #>"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":null,"dir":"Reference","previous_headings":"","what":"Default undesirable functions and operators — all_undesirable_functions","title":"Default undesirable functions and operators — all_undesirable_functions","text":"Lists function names operators undesirable_function_linter() undesirable_operator_linter(). list default elements another contains available elements. Use modify_defaults() produce custom list.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default undesirable functions and operators — all_undesirable_functions","text":"","code":"all_undesirable_functions default_undesirable_functions all_undesirable_operators default_undesirable_operators"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default undesirable functions and operators — all_undesirable_functions","text":"named list character strings.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Default undesirable functions and operators — all_undesirable_functions","text":"following functions sometimes regarded undesirable: attach() modifies global search path. Use roxygen2's @importFrom statement packages, :: scripts. browser() pauses execution run likely leftover debugging. removed. debug() traps function causes execution pause function run. removed. debugcall() works similarly debug(), causing execution pause. removed. debugonce() useful interactive debugging. removed. detach() modifies global search path. Detaching environments search path rarely necessary production code. ifelse() type stable. Use /else block scalar logic, use dplyr::if_else()/data.table::fifelse() type stable vectorized logic. .libPaths() permanently modifies library location. Use withr::with_libpaths() temporary change instead. library() modifies global search path. Use roxygen2's @importFrom statement packages, :: scripts. loadNamespace() provide easy way signal failures. Use return value requireNamespace() instead. mapply() type stable. Use Map() guarantee list returned simplify accordingly. options() permanently modifies session options. Use withr::with_options() temporary change instead. par() permanently modifies graphics device parameters. Use withr::with_par() temporary change instead. require() modifies global search path. Use roxygen2's @importFrom statement packages, library() :: scripts. sapply() type stable. Use vapply() appropriate FUN.VALUE= argument obtain type stable simplification. setwd() modifies global working directory. Use withr::with_dir() temporary change instead. sink() permanently redirects output. Use withr::with_sink() temporary redirection instead. source() loads code global environment unless local = TRUE used, can cause unexpected behavior. substring() replaced substr() appropriate stop= value. Sys.setenv() permanently modifies global environment variables. Use withr::with_envvar() temporary change instead. Sys.setlocale() permanently modifies session locale. Use withr::with_locale() temporary change instead. trace() traps function causes execution arbitrary code function run. removed. undebug() useful interactive debugging debug(). removed. untrace() useful interactive debugging trace(). removed. following operators sometimes regarded undesirable: ::: accesses non-exported functions inside packages. Code relying likely break future versions package functions part public interface may changed removed maintainers without notice. Use public functions via :: instead. <<- ->> assign outside current environment way can hard reason . Prefer fully-encapsulated functions wherever possible, , necessary, assign specific environment assign(). Recall can create environment desired scope new.env().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated linters — deprecated_linters","title":"Deprecated linters — deprecated_linters","text":"Linters deprecated provided backwards compatibility . linters excluded linters_with_tags() default.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Deprecated linters — deprecated_linters","text":"following linters tagged 'deprecated': closed_curly_linter consecutive_stopifnot_linter no_tab_linter open_curly_linter paren_brace_linter semicolon_terminator_linter single_quotes_linter unneeded_concatenation_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Duplicate argument linter — duplicate_argument_linter","title":"Duplicate argument linter — duplicate_argument_linter","text":"Check duplicate arguments function calls. cases run-time errors (e.g. mean(x = 1:5, x = 2:3)), otherwise linter used discourage explicitly providing duplicate names objects (e.g. c(= 1, = 2)). Duplicate-named objects hard work programmatically typically avoided.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"duplicate_argument_linter(except = c(\"mutate\", \"transmute\"))"},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Duplicate argument linter — duplicate_argument_linter","text":"except character vector function names exceptions. Defaults functions allow sequential updates variables, currently dplyr::mutate() dplyr::transmute().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Duplicate argument linter — duplicate_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"# will produce lints lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[duplicate_argument_linter] Duplicate arguments in function call. lint( text = \"fun(arg = 1, arg = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[duplicate_argument_linter] Duplicate arguments in function call. # okay lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter(except = \"list\") ) lint( text = \"df %>% dplyr::mutate(x = a + b, x = x + d)\", linters = duplicate_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Efficiency linters — efficiency_linters","title":"Efficiency linters — efficiency_linters","text":"Linters highlighting code efficiency problems, unnecessary function calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Efficiency linters — efficiency_linters","text":"following linters tagged 'efficiency': any_duplicated_linter any_is_na_linter boolean_arithmetic_linter fixed_regex_linter ifelse_censor_linter inner_combine_linter lengths_linter literal_coercion_linter matrix_apply_linter nested_ifelse_linter outer_negation_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter seq_linter sort_linter string_boundary_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unnecessary_lambda_linter vector_logic_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block assignment of {} — empty_assignment_linter","title":"Block assignment of {} — empty_assignment_linter","text":"Assignment {} assignment NULL; use latter clarity. Closely related: unnecessary_concatenation_linter().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"empty_assignment_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block assignment of {} — empty_assignment_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"# will produce lints lint( text = \"x <- {}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. writeLines(\"x = {\\n}\") #> x = { #> } lint( text = \"x = {\\n}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. # okay lint( text = \"x <- { 3 + 4 }\", linters = empty_assignment_linter() ) lint( text = \"x <- NULL\", linters = empty_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality check with NA linter — equals_na_linter","title":"Equality check with NA linter — equals_na_linter","text":"Check x == NA x != NA. usage almost surely incorrect -- checks missing values done .na().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality check with NA linter — equals_na_linter","text":"","code":"equals_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Equality check with NA linter — equals_na_linter","text":"common_mistakes, correctness, default, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality check with NA linter — equals_na_linter","text":"","code":"# will produce lints lint( text = \"x == NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or !=) lint( text = \"x != NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or !=) # okay lint( text = \"is.na(x)\", linters = equals_na_linter() ) lint( text = \"!is.na(x)\", linters = equals_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":null,"dir":"Reference","previous_headings":"","what":"Exclude lines or files from linting — exclude","title":"Exclude lines or files from linting — exclude","text":"Exclude lines files linting","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Exclude lines or files from linting — exclude","text":"","code":"exclude(lints, exclusions = settings$exclusions, linter_names = NULL, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Exclude lines or files from linting — exclude","text":"lints need filtered. exclusions manually specified exclusions linter_names character vector names active linters, used parsing inline exclusions. ... additional arguments passed parse_exclusions()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Exclude lines or files from linting — exclude","text":"Exclusions can specified three different ways. single line source file. default: # nolint, possibly followed listing linters exclude. listing missing, linters excluded line. default listing format # nolint: linter_name, linter2_name.. may anything colon line exclusion tag listing must terminated full stop (.) linter list respected. line range source file. default: # nolint start, # nolint end. # nolint start accepts linter lists form # nolint. exclusions parameter, named list files named lists linters lines exclude , named list files lines exclude, just filenames want exclude entire file, directory names want exclude files directory.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Code executing linters — executing_linters","title":"Code executing linters — executing_linters","text":"Linters evaluate parts linted code, loading referenced packages. linters used untrusted code, may need dependencies linted package project available order function correctly.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Code executing linters — executing_linters","text":"following linters tagged 'executing': namespace_linter object_length_linter object_name_linter object_usage_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"testthat::expect_gt(), testthat::expect_gte(), testthat::expect_lt(), testthat::expect_lte(), testthat::expect_equal() exist specifically testing comparisons two objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"expect_comparison_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x > y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y). lint( text = \"expect_true(x <= y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y). lint( text = \"expect_true(x == (y == 2))\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y). # okay lint( text = \"expect_gt(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_lte(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_identical(x, y == 2)\", linters = expect_comparison_linter() ) lint( text = \"expect_true(x < y | x > y^2)\", linters = expect_comparison_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter enforces usage testthat::expect_identical() default expectation comparisons testthat suite. expect_true(identical(x, y)) equivalent unadvised method test. , testthat::expect_equal() used expect_identical() inappropriate, .e., x y need numerically equivalent instead fully identical (case, provide tolerance= argument expect_equal() explicitly). also applies inconvenient check full equality (e.g., names can ignored, case ignore_attr = \"names\" supplied expect_equal() (, 2nd edition, check.attributes = FALSE).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"expect_identical_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter allows expect_equal() three circumstances: named argument set (e.g. ignore_attr tolerance) Comparison made explicit decimal, e.g. expect_equal(x, 1.0) (implicitly setting tolerance) ... passed (wrapper functions might set arguments ignore_attr tolerance)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, y)\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. lint( text = \"expect_true(identical(x, y))\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. # okay lint( text = \"expect_identical(x, y)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, check.attributes = FALSE)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, tolerance = 1e-6)\", linters = expect_identical_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"testthat::expect_length() exists specifically testing length() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"expect_length_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(length(x), 2L)\", linters = expect_length_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n) # okay lint( text = \"expect_length(x, 2L)\", linters = expect_length_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint expectation — expect_lint","title":"Lint expectation — expect_lint","text":"expectation function test lints produced lint satisfy number checks.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint expectation — expect_lint","text":"","code":"expect_lint(content, checks, ..., file = NULL, language = \"en\")"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lint expectation — expect_lint","text":"content character vector file content linted, vector element representing line text. checks checks performed: NULL check lints returned. single string regex object check single lint returned matching message. named list check single lint returned fields match. Accepted fields taken Lint(). list named lists multiple lints returned, check matches checks corresponding named list (described point ). Named vectors also accepted instead named lists, compatibility feature recommended new code. ... arguments passed lint(), e.g. linters cache use. file NULL, read content specified file rather content. language temporarily override Rs LANGUAGE envvar, controlling localization base R error messages. makes testing reproducible systems irrespective native R language setting.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lint expectation — expect_lint","text":"NULL, invisibly.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint expectation — expect_lint","text":"","code":"# no expected lint expect_lint(\"a\", NULL, trailing_blank_lines_linter()) # one expected lint expect_lint(\"a\\n\", \"superfluous\", trailing_blank_lines_linter()) expect_lint(\"a\\n\", list(message = \"superfluous\", line_number = 2), trailing_blank_lines_linter()) # several expected lints expect_lint(\"a\\n\\n\", list(\"superfluous\", \"superfluous\"), trailing_blank_lines_linter()) expect_lint( \"a\\n\\n\", list( list(message = \"superfluous\", line_number = 2), list(message = \"superfluous\", line_number = 3) ), trailing_blank_lines_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":null,"dir":"Reference","previous_headings":"","what":"Test that the package is lint free — expect_lint_free","title":"Test that the package is lint free — expect_lint_free","text":"function thin wrapper around lint_package simply tests lints package. can used ensure tests fail package contains lints.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test that the package is lint free — expect_lint_free","text":"","code":"expect_lint_free(...)"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test that the package is lint free — expect_lint_free","text":"... arguments passed lint_package()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"testthat::expect_named() exists specifically testing names() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"expect_named_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(names(x), \"a\")', linters = expect_named_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n) # okay lint( text = 'expect_named(x, \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(colnames(x), \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(dimnames(x), \"a\")', linters = expect_named_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"testthat::expect_false() exists specifically testing output FALSE. testthat::expect_true() can also used tests negating output, better use tailored function instead. reverse also true -- use expect_false() instead expect_true(!).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"expect_not_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"# will produce lints lint( text = \"expect_true(!x)\", linters = expect_not_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa. # okay lint( text = \"expect_false(x)\", linters = expect_not_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_null for checking NULL — expect_null_linter","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"Require usage expect_null(x) expect_equal(x, NULL) similar usages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"expect_null_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"testthat::expect_null() exists specifically testing NULL objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_equal(x, NULL) lint( text = \"expect_identical(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_identical(x, NULL) lint( text = \"expect_true(is.null(x))\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_true(is.null(x)) # okay lint( text = \"expect_null(x)\", linters = expect_null_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s3_class() — expect_s3_class_linter","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"testthat::expect_s3_class() exists specifically testing class S3 objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"expect_s3_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(class(x), \"data.frame\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. lint( text = 'expect_equal(class(x), \"numeric\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. # okay lint( text = 'expect_s3_class(x, \"data.frame\")', linters = expect_s3_class_linter() ) lint( text = 'expect_type(x, \"double\")', linters = expect_s3_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"testthat::expect_s4_class() exists specifically testing class S4 objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"expect_s4_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"# will produce lints lint( text = 'expect_true(is(x, \"Matrix\"))', linters = expect_s4_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s4_class_linter] expect_s4_class(x, k) is better than expect_true(is(x, k)). Note also expect_s3_class() available for testing S3 objects. # okay lint( text = 'expect_s4_class(x, \"Matrix\")', linters = expect_s4_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"testthat::expect_true() testthat::expect_false() exist specifically testing TRUE/FALSE value object. testthat::expect_equal() testthat::expect_identical() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"expect_true_false_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, TRUE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE) lint( text = \"expect_equal(x, FALSE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE) # okay lint( text = \"expect_true(x)\", linters = expect_true_false_linter() ) lint( text = \"expect_false(x)\", linters = expect_true_false_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"testthat::expect_type() exists specifically testing storage type objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"expect_type_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t) lint( text = 'expect_identical(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t) # okay lint( text = 'expect_type(x, \"double\")', linters = expect_type_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Extraction operator linter — extraction_operator_linter","title":"Extraction operator linter — extraction_operator_linter","text":"Check [[ operator used extracting single element object, [ (subsetting) $ (interactive use).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extraction operator linter — extraction_operator_linter","text":"","code":"extraction_operator_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extraction operator linter — extraction_operator_linter","text":"three subsetting operators R ([[, [, $) interact differently different data structures (atomic vector, list, data frame, etc.). reasons prefer [[ operator [ $ want extract element data frame list: Subsetting list [ always returns smaller list, [[ returns list element. Subsetting named atomic vector [ returns named vector, [[ returns vector element. Subsetting data frame (tibble) [ type unstable; can return vector data frame. [[, hand, always returns vector. data frame (tibble), $ partial matching (e.g. df$subset df$abc), can source bugs. [[ partial matching. data frames (tibbles), irrespective size, [[ operator slower $. lists, however, reverse true.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Extraction operator linter — extraction_operator_linter","text":"Subsetting chapter Advanced R (Wickham, 2019).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Extraction operator linter — extraction_operator_linter","text":"best_practices, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extraction operator linter — extraction_operator_linter","text":"","code":"# will produce lints lint( text = 'iris[\"Species\"]', linters = extraction_operator_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[extraction_operator_linter] Use `[[` instead of `[` to extract an element. lint( text = \"iris$Species\", linters = extraction_operator_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[extraction_operator_linter] Use `[[` instead of `$` to extract an element. # okay lint( text = 'iris[[\"Species\"]]', linters = extraction_operator_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"Invoking regular expression engine overkill cases search pattern involves static patterns.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"fixed_regex_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"NB: stringr functions, means wrapping pattern stringr::fixed(). NB: linter likely able distinguish every possible case fixed regular expression preferable, rather seeks identify likely cases. never report false positives, however; please report false positives error.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"# will produce lints code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x) lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \".\" with fixed = TRUE. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \"a*b\" with fixed = TRUE. code_lines <- 'stringr::str_subset(x, \"\\\\\\\\$\")' writeLines(code_lines) #> stringr::str_subset(x, \"\\\\$\") lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use stringr::fixed(\"$\") as the pattern. lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \"Munich\" with fixed = TRUE. # okay code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x, fixed = TRUE)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x, fixed = TRUE) lint( text = code_lines, linters = fixed_regex_linter() ) lint( text = 'grepl(\"a*b\", x, fixed = TRUE)', linters = fixed_regex_linter() ) lint( text = 'stringr::str_subset(x, stringr::fixed(\"$\"))', linters = fixed_regex_linter() ) lint( text = 'grepl(\"Munich\", address, fixed = TRUE)', linters = fixed_regex_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"(x x) poor choice indexing variable. overwrites x calling scope confusing read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"for_loop_index_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"best_practices, readability, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"# will produce lints lint( text = \"for (x in x) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. lint( text = \"for (x in foo(x, y)) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. # okay lint( text = \"for (xi in x) { TRUE }\", linters = for_loop_index_linter() ) lint( text = \"for (col in DF$col) { TRUE }\", linters = for_loop_index_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function argument linter — function_argument_linter","title":"Function argument linter — function_argument_linter","text":"Check arguments defaults come last function declarations, per tidyverse design guide. Changing argument order can breaking change. alternative changing argument order instead set default arguments NULL.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function argument linter — function_argument_linter","text":"","code":"function_argument_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function argument linter — function_argument_linter","text":"best_practices, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function argument linter — function_argument_linter","text":"","code":"# will produce lints lint( text = \"function(y = 1, z = 2, x) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[function_argument_linter] Arguments without defaults should come before arguments with defaults. lint( text = \"function(x, y, z = 1, ..., w) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=28::file=,line=1,col=28,[function_argument_linter] Arguments without defaults should come before arguments with defaults. # okay lint( text = \"function(x, y = 1, z = 2) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, w, z = 1, ...) {}\", linters = function_argument_linter() ) lint( text = \"function(y = 1, z = 2, x = NULL) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, z = 1, ..., w = NULL) {}\", linters = function_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function left parentheses linter — function_left_parentheses_linter","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Check left parentheses function call spaces (e.g. mean (1:3)). Although syntactically valid, makes code difficult read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"function_left_parentheses_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Exceptions made control flow functions (, , etc.).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function left parentheses linter — function_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"mean (x)\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. lint( text = \"stats::sd(c (x, y, z))\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. # okay lint( text = \"mean(x)\", linters = function_left_parentheses_linter() ) lint( text = \"stats::sd(c(x, y, z))\", linters = function_left_parentheses_linter() ) lint( text = \"foo <- function(x) (x + 1)\", linters = function_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"return(x <- ...) either distracting (x ignored), confusing (assigning x side effect muddled dual-purpose expression).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"function_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"# will produce lints lint( text = \"foo <- function(x) return(y <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. lint( text = \"foo <- function(x) return(x <<- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. writeLines(\"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\") #> e <- new.env() #> foo <- function(x) return(e$val <- x + 1) lint( text = \"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=2,col=27::file=,line=2,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. # okay lint( text = \"foo <- function(x) return(x + 1)\", linters = function_return_linter() ) code_lines <- \" foo <- function(x) { x <<- x + 1 return(x) } \" lint( text = code_lines, linters = function_return_linter() ) code_lines <- \" e <- new.env() foo <- function(x) { e$val <- x + 1 return(e$val) } \" writeLines(code_lines) #> #> e <- new.env() #> foo <- function(x) { #> e$val <- x + 1 #> return(e$val) #> } #> lint( text = code_lines, linters = function_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract text from STR_CONST nodes — get_r_string","title":"Extract text from STR_CONST nodes — get_r_string","text":"Convert STR_CONST text() values R strings. useful account arbitrary character literals valid since R 4.0, e.g. R\"------[hello]------\", parsed R \"hello\". quite cumbersome write XPaths allowing strings like , whenever linter logic requires testing STR_CONST node's value, use function. NB: also properly vectorized s, accepts variety inputs. Empty inputs become NA outputs, helps ensure length(get_r_string(s)) == length(s).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract text from STR_CONST nodes — get_r_string","text":"","code":"get_r_string(s, xpath = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract text from STR_CONST nodes — get_r_string","text":"s input string strings. s xml_node xml_nodeset xpath NULL, extract string value xml2::xml_text(). s xml_node xml_nodeset xpath specified, extracted xml2::xml_find_chr(). xpath XPath, passed xml2::xml_find_chr() wrapping string().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract text from STR_CONST nodes — get_r_string","text":"","code":"tmp <- withr::local_tempfile(lines = \"c('a', 'b')\") expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content #> Warning: cannot open file '/tmp/RtmpyuoqE0/file169079f85809': No such file or directory #> Error in file(con, \"r\"): cannot open the connection writeLines(as.character(expr_as_xml)) #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found get_r_string(expr_as_xml, \"expr[2]\") # \"a\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found get_r_string(expr_as_xml, \"expr[3]\") # \"b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found # more importantly, extract strings under R>=4 raw strings tmp4.0 <- withr::local_tempfile(lines = \"c(R'(a\\\\b)', R'--[a\\\\\\\"\\'\\\"\\\\b]--')\") expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content #> Warning: cannot open file '/tmp/RtmpyuoqE0/file16904e7f04a9': No such file or directory #> Error in file(con, \"r\"): cannot open the connection writeLines(as.character(expr_as_xml4.0)) #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found get_r_string(expr_as_xml4.0, \"expr[2]\") # \"a\\b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found get_r_string(expr_as_xml4.0, \"expr[3]\") # \"a\\\\\"'\\\"\\b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":null,"dir":"Reference","previous_headings":"","what":"Parsed sourced file from a filename — get_source_expressions","title":"Parsed sourced file from a filename — get_source_expressions","text":"object given input linter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"get_source_expressions(filename, lines = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Parsed sourced file from a filename — get_source_expressions","text":"filename file parsed. lines character vector lines. NULL, filename read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Parsed sourced file from a filename — get_source_expressions","text":"list three components: expressions list n+1 objects. first n elements correspond expression filename, consist list 9 elements: filename (character) line (integer) line filename expression begins column (integer) column filename expression begins lines (named character) vector lines spanned expression, named line number corresponding filename parsed_content (data.frame) given utils::getParseData() expression xml_parsed_content (xml_document) XML parse tree expression given xmlparsedata::xml_parse_data() content (character) lines single string (split across lines) (Deprecated) find_line (function) function returning lines expression (Deprecated) find_column (function) similar function columns final element expressions list corresponding full file consisting 6 elements: filename (character) file_lines (character) readLines() output file content (character) .R files, file_lines; .Rmd .qmd scripts, extracted R source code (text) full_parsed_content (data.frame) given utils::getParseData() full content full_xml_parsed_content (xml_document) XML parse tree expressions given xmlparsedata::xml_parse_data() terminal_newline (logical) records whether filename terminal newline (determined readLines() producing corresponding warning) error Lint object describing parsing error. lines readLines() output file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Parsed sourced file from a filename — get_source_expressions","text":"file read using encoding setting. setting found taking first valid result following locations encoding key usual lintr configuration settings. Encoding field Package DESCRIPTION file parent directory. Encoding field R Project .Rproj file parent directory. \"UTF-8\" fallback.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) get_source_expressions(tmp) #> Warning: cannot open file '/tmp/RtmpyuoqE0/file16907e2a0f4b': No such file or directory #> Error in file(con, \"r\"): cannot open the connection"},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":null,"dir":"Reference","previous_headings":"","what":"Get parsed IDs by token — ids_with_token","title":"Get parsed IDs by token — ids_with_token","text":"Gets source IDs (row indices) corresponding given token.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get parsed IDs by token — ids_with_token","text":"","code":"ids_with_token(source_expression, value, fun = `==`, source_file = NULL) with_id(source_expression, id, source_file)"},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get parsed IDs by token — ids_with_token","text":"source_expression list source expressions, result call get_source_expressions(), desired filename. value Character. String corresponding token search . example: \"SYMBOL\" \"FUNCTION\" \"EQ_FORMALS\" \"$\" \"(\" fun additional flexibility, function search token column parsed_content. Typically == %%. source_file (DEPRECATED) source_expression. removed. id Integer. index corresponding desired row parsed_content.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get parsed IDs by token — ids_with_token","text":"ids_with_token: indices parsed_content data frame entry list source expressions. Indices correspond rows fun evaluates TRUE value token column. with_id: data frame corresponding row(s) specified id.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Get parsed IDs by token — ids_with_token","text":"with_id(): Return row parsed_content entry [get_source_expressions]() object. Typically used conjunction ids_with_token iterate rows containing desired tokens.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get parsed IDs by token — ids_with_token","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) source_exprs <- get_source_expressions(tmp) #> Warning: cannot open file '/tmp/RtmpyuoqE0/file1690a30eb69': No such file or directory #> Error in file(con, \"r\"): cannot open the connection ids_with_token(source_exprs$expressions[[1L]], value = \"SYMBOL\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found with_id(source_exprs$expressions[[1L]], 2L) #> Error in eval(expr, envir, enclos): object 'source_exprs' not found"},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"ifelse(x > M, M, x) pmin(x, M), harder read requires several passes vector.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"","code":"ifelse_censor_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"goes similar ways censor vector, e.g. ifelse(x <= M, x, M) pmin(x, M), ifelse(x < m, m, x) pmax(x, m), ifelse(x >= m, x, m) pmax(x, m).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"","code":"# will produce lints lint( text = \"ifelse(5:1 < pi, 5:1, pi)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmin(x, y) is preferable to ifelse(x < y, x, y). lint( text = \"ifelse(x > 0, x, 0)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmax(x, y) is preferable to ifelse(x > y, x, y). # okay lint( text = \"pmin(5:1, pi)\", linters = ifelse_censor_linter() ) lint( text = \"pmax(x, 0)\", linters = ifelse_censor_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Avoid implicit assignment in function calls — implicit_assignment_linter","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"Assigning inside function calls makes code difficult read, avoided, except functions capture side-effects (e.g. capture.output()).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"implicit_assignment_linter( except = c(\"bquote\", \"expression\", \"expr\", \"quo\", \"quos\", \"quote\") )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"except character vector functions excluded linting.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"best_practices, configurable, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"# will produce lints lint( text = \"if (x <- 1L) TRUE\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. lint( text = \"mean(x <- 1:4)\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. # okay writeLines(\"x <- 1L\\nif (x) TRUE\") #> x <- 1L #> if (x) TRUE lint( text = \"x <- 1L\\nif (x) TRUE\", linters = implicit_assignment_linter() ) writeLines(\"x <- 1:4\\nmean(x)\") #> x <- 1:4 #> mean(x) lint( text = \"x <- 1:4\\nmean(x)\", linters = implicit_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Implicit integer linter — implicit_integer_linter","title":"Implicit integer linter — implicit_integer_linter","text":"Check integers explicitly typed using form 1L instead 1.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Implicit integer linter — implicit_integer_linter","text":"","code":"implicit_integer_linter(allow_colon = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Implicit integer linter — implicit_integer_linter","text":"allow_colon Logical, default FALSE. TRUE, expressions involving : throw lint regardless whether inputs implicitly integers.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Implicit integer linter — implicit_integer_linter","text":"best_practices, configurable, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Implicit integer linter — implicit_integer_linter","text":"","code":"# will produce lints lint( text = \"x <- 1\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. lint( text = \"x[2]\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=4::file=,line=1,col=4,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. lint( text = \"1:10\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. # okay lint( text = \"x <- 1.0\", linters = implicit_integer_linter() ) lint( text = \"x <- 1L\", linters = implicit_integer_linter() ) lint( text = \"x[2L]\", linters = implicit_integer_linter() ) lint( text = \"1:10\", linters = implicit_integer_linter(allow_colon = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that indentation is consistent — indentation_linter","title":"Check that indentation is consistent — indentation_linter","text":"Check indentation consistent","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that indentation is consistent — indentation_linter","text":"","code":"indentation_linter( indent = 2L, hanging_indent_style = c(\"tidy\", \"always\", \"never\"), assignment_as_infix = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that indentation is consistent — indentation_linter","text":"indent Number spaces, code block indented relative parent code block. Used multi-line code blocks ({ ... }), function calls (( ... )) extractions ([ ... ], [[ ... ]]). Defaults 2. hanging_indent_style Indentation style multi-line function calls arguments first line. Defaults tidyverse style, .e. block indent used function call terminates ) separate line hanging indent . Note function multi-line function calls without arguments first line always expected block-indented arguments. hanging_indent_style \"tidy\", multi-line function definitions expected double-indented first line function definition contains arguments closing parenthesis line. assignment_as_infix Treat <- regular (.e. left-associative) infix operator? means, infix operators right hand side assignment trigger second level indentation:","code":"# complies to any style map( x, f, additional_arg = 42 ) # complies to \"tidy\" and \"never\" map(x, f, additional_arg = 42 ) # complies to \"always\" map(x, f, additional_arg = 42 ) # complies to \"tidy\" and \"always\" map(x, f, additional_arg = 42) # complies to \"never\" map(x, f, additional_arg = 42) # complies to \"tidy\" function( a, b) { # body } # complies to any style variable <- a %+% b %+% c # complies to assignment_as_infix = TRUE variable <- a %+% b %+% c # complies to assignment_as_infix = FALSE variable <- a %+% b %+% c"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check that indentation is consistent — indentation_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check that indentation is consistent — indentation_linter","text":"","code":"# will produce lints code_lines <- \"if (TRUE) {\\n1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=0::file=,line=2,col=0,[indentation_linter] Indentation should be 2 spaces but is 0 spaces. code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"always\") ) #> ::warning file=,line=2,col=2::file=,line=2,col=2,[indentation_linter] Hanging indent should be 4 spaces but is 2 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"never\") ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. # okay code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter() ) code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter(indent = 4) )"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Infix spaces linter — infix_spaces_linter","title":"Infix spaces linter — infix_spaces_linter","text":"Check infix operators surrounded spaces. Enforces corresponding Tidyverse style guide rule; see https://style.tidyverse.org/syntax.html#infix-operators.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"infix_spaces_linter(exclude_operators = NULL, allow_multiple_spaces = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Infix spaces linter — infix_spaces_linter","text":"exclude_operators Character vector operators exclude consideration linting. Default include following \"low-precedence\" operators: +, -, ~, >, >=, <, <=, ==, !=, &, &&, |, ||, <-, :=, <<-, ->, ->>, =, /, *, infix operator (exclude infixes passing \"%%\"). Note <-, :=, <<- included/excluded group (indicated passing \"<-\"), -> ->> (viz, \"->\"), = assignment setting arguments calls treated . allow_multiple_spaces Logical, default TRUE. FALSE, usage like x = 2 also linted; excluded default usage can sometimes used better code alignment, allowed style guide.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Infix spaces linter — infix_spaces_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"# will produce lints lint( text = \"x<-1L\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators. lint( text = \"1:4 %>%sum()\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[infix_spaces_linter] Put spaces around all infix operators. # okay lint( text = \"x <- 1L\", linters = infix_spaces_linter() ) lint( text = \"1:4 %>% sum()\", linters = infix_spaces_linter() ) code_lines <- \" ab <- 1L abcdef <- 2L \" writeLines(code_lines) #> #> ab <- 1L #> abcdef <- 2L #> lint( text = code_lines, linters = infix_spaces_linter(allow_multiple_spaces = TRUE) ) lint( text = \"a||b\", linters = infix_spaces_linter(exclude_operators = \"||\") )"},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":".Date(c(, b)) logically equivalent c(.Date(), .Date(b)). equivalence holds several vectorized functions like .POSIXct() math functions like sin(). former preferred expensive part operation (.Date()) applied .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"","code":"inner_combine_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"","code":"# will produce lints lint( text = \"c(log10(x), log10(y), log10(z))\", linters = inner_combine_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[inner_combine_linter] Combine inputs to vectorized functions first to take full advantage of vectorization, e.g., log10(c(x, y)) only runs the more expensive log10() once as compared to c(log10(x), log10(y)). # okay lint( text = \"log10(c(x, y, z))\", linters = inner_combine_linter() ) lint( text = \"c(log(x, base = 10), log10(x, base = 2))\", linters = inner_combine_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":null,"dir":"Reference","previous_headings":"","what":"Is this an expression- or a file-level source object? — is_lint_level","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"Helper determining whether current source_expression contains expressions current file, just single expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"is_lint_level(source_expression, level = c(\"expression\", \"file\"))"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"source_expression parsed expression object, .e., element object returned get_source_expressions(). level level expression tested? \"expression\" means individual expression, \"file\" means expressions current file available.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) source_exprs <- get_source_expressions(tmp) #> Warning: cannot open file '/tmp/RtmpyuoqE0/file16904d2e0e96': No such file or directory #> Error in file(con, \"r\"): cannot open the connection is_lint_level(source_exprs$expressions[[1L]], level = \"expression\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[1L]], level = \"file\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[3L]], level = \"expression\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[3L]], level = \"file\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found"},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":".numeric() returns TRUE typeof(x) double integer -- testing .numeric(x) || .integer(x) thus redundant.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"","code":"is_numeric_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"NB: linter plays well class_equals_linter(), can help avoid .numeric() equivalents like (class(x) == c(\"numeric\", \"integer\")).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"","code":"# will produce lints lint( text = \"is.numeric(y) || is.integer(y)\", linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as is.numeric(x) || is.integer(x). Use is.double(x) to test for objects stored as 64-bit floating point. lint( text = 'class(z) %in% c(\"numeric\", \"integer\")', linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as class(x) %in% c(\"integer\", \"numeric\"). Use is.double(x) to test for objects stored as 64-bit floating point. # okay lint( text = \"is.numeric(y) || is.factor(y)\", linters = is_numeric_linter() ) lint( text = 'class(z) %in% c(\"numeric\", \"integer\", \"factor\")', linters = is_numeric_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of lengths() where possible — lengths_linter","title":"Require usage of lengths() where possible — lengths_linter","text":"lengths() function added base R version 3.2.0 get length element list. equivalent sapply(x, length), faster readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of lengths() where possible — lengths_linter","text":"","code":"lengths_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of lengths() where possible — lengths_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of lengths() where possible — lengths_linter","text":"","code":"# will produce lints lint( text = \"sapply(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"vapply(x, length, integer(1L))\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"purrr::map_int(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. # okay lint( text = \"lengths(x)\", linters = lengths_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Line length linter — line_length_linter","title":"Line length linter — line_length_linter","text":"Check line length comments code less length.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Line length linter — line_length_linter","text":"","code":"line_length_linter(length = 80L)"},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Line length linter — line_length_linter","text":"length maximum line length allowed. Default 80L (Hollerith limit).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Line length linter — line_length_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Line length linter — line_length_linter","text":"","code":"# will produce lints lint( text = strrep(\"x\", 23L), linters = line_length_linter(length = 20L) ) #> ::warning file=,line=1,col=21::file=,line=1,col=21,[line_length_linter] Lines should not be more than 20 characters. # okay lint( text = strrep(\"x\", 21L), linters = line_length_linter(length = 40L) )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a lint object — lint-s3","title":"Create a lint object — lint-s3","text":"Create lint object","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a lint object — lint-s3","text":"","code":"Lint( filename, line_number = 1L, column_number = 1L, type = c(\"style\", \"warning\", \"error\"), message = \"\", line = \"\", ranges = NULL, linter = \"\" )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a lint object — lint-s3","text":"filename path source file linted. line_number line number lint occurred. column_number column number lint occurred. type type lint. message message used describe lint error line code source lint occurred ranges list ranges line emphasized. linter deprecated. longer used.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a lint object — lint-s3","text":"object class c(\"lint\", \"list\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint a file, directory, or package — lint","title":"Lint a file, directory, or package — lint","text":"lint() lints single file. lint_dir() lints files directory. lint_package() lints likely locations R files package, .e. R/, tests/, inst/, vignettes/, data-raw/, demo/, exec/.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint a file, directory, or package — lint","text":"","code":"lint( filename, linters = NULL, ..., cache = FALSE, parse_settings = TRUE, text = NULL ) lint_dir( path = \".\", ..., relative_path = TRUE, exclusions = list(\"renv\", \"packrat\"), pattern = rex::rex(\".\", one_of(\"Rr\"), or(\"\", \"html\", \"md\", \"nw\", \"rst\", \"tex\", \"txt\"), end), parse_settings = TRUE ) lint_package( path = \".\", ..., relative_path = TRUE, exclusions = list(\"R/RcppExports.R\"), parse_settings = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lint a file, directory, or package — lint","text":"filename either filename file lint, character string inline R code linting. latter (inline data) applies whenever filename newline character (\\n). linters named list linter functions apply. See linters full list default available linters. ... Provide additional arguments passed : exclude() (case lint(); e.g. lints exclusions) lint() (case lint_dir() lint_package(); e.g. linters cache) cache given logical, toggle caching lint results. passed character string, store cache directory. parse_settings whether try parse settings. text Optional argument supplying string lines directly, e.g. file already memory linting done ad hoc. path base directory project (lint_dir()) package (lint_package()). relative_path TRUE, file paths printed using path relative base directory. FALSE, use full absolute path. exclusions exclusions exclude(), relative package path. pattern pattern files, default take files extensions .R, .Rmd, .qmd, .Rnw, .Rhtml, .Rrst, .Rtex, .Rtxt allowing lowercase r (.r, ...).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lint a file, directory, or package — lint","text":"object class c(\"lints\", \"list\"), element \"list\" object.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Lint a file, directory, or package — lint","text":"Read vignette(\"lintr\") learn configure linters run default. Note files contain unparseable encoding problems, encoding problem linted avoid unintelligible error messages linters.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint a file, directory, or package — lint","text":"","code":"f <- withr::local_tempfile(lines = \"a=1\", fileext = \"R\") lint(f) # linting a file #> Warning: cannot open file '/tmp/RtmpyuoqE0/file169025dd8bedR': No such file or directory #> Error in file(con, \"r\"): cannot open the connection lint(\"a = 123\\n\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. lint(text = \"a = 123\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. if (FALSE) { lint_dir() lint_dir( linters = list(semicolon_linter()), exclusions = list( \"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\", \"renv\" ) ) } if (FALSE) { lint_package() lint_package( linters = linters_with_defaults(semicolon_linter = semicolon_linter()), exclusions = list(\"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\") ) }"},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Available linters — linters","title":"Available linters — linters","text":"variety linters available lintr. popular ones readily accessible default_linters(). Within lint() function call, linters use initialized provided arguments fed source file (provided get_source_expressions()). data frame available linters can retrieved using available_linters(). Documentation linters structured tags allow easier discovery; see also available_tags().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Available linters — linters","text":"following tags exist: best_practices (50 linters) common_mistakes (7 linters) configurable (29 linters) consistency (18 linters) correctness (7 linters) default (25 linters) deprecated (8 linters) efficiency (23 linters) executing (5 linters) package_development (14 linters) readability (47 linters) robustness (14 linters) style (34 linters)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Available linters — linters","text":"following linters exist: absolute_path_linter (tags: best_practices, configurable, robustness) any_duplicated_linter (tags: best_practices, efficiency) any_is_na_linter (tags: best_practices, efficiency) assignment_linter (tags: configurable, consistency, default, style) backport_linter (tags: configurable, package_development, robustness) boolean_arithmetic_linter (tags: best_practices, efficiency, readability) brace_linter (tags: configurable, default, readability, style) class_equals_linter (tags: best_practices, consistency, robustness) commas_linter (tags: default, readability, style) commented_code_linter (tags: best_practices, default, readability, style) condition_message_linter (tags: best_practices, consistency) conjunct_test_linter (tags: best_practices, configurable, package_development, readability) consecutive_assertion_linter (tags: consistency, readability, style) cyclocomp_linter (tags: best_practices, configurable, default, readability, style) duplicate_argument_linter (tags: common_mistakes, configurable, correctness) empty_assignment_linter (tags: best_practices, readability) equals_na_linter (tags: common_mistakes, correctness, default, robustness) expect_comparison_linter (tags: best_practices, package_development) expect_identical_linter (tags: package_development) expect_length_linter (tags: best_practices, package_development, readability) expect_named_linter (tags: best_practices, package_development, readability) expect_not_linter (tags: best_practices, package_development, readability) expect_null_linter (tags: best_practices, package_development) expect_s3_class_linter (tags: best_practices, package_development) expect_s4_class_linter (tags: best_practices, package_development) expect_true_false_linter (tags: best_practices, package_development, readability) expect_type_linter (tags: best_practices, package_development) extraction_operator_linter (tags: best_practices, style) fixed_regex_linter (tags: best_practices, efficiency, readability) for_loop_index_linter (tags: best_practices, readability, robustness) function_argument_linter (tags: best_practices, consistency, style) function_left_parentheses_linter (tags: default, readability, style) function_return_linter (tags: best_practices, readability) ifelse_censor_linter (tags: best_practices, efficiency) implicit_assignment_linter (tags: best_practices, configurable, readability, style) implicit_integer_linter (tags: best_practices, configurable, consistency, style) indentation_linter (tags: configurable, default, readability, style) infix_spaces_linter (tags: configurable, default, readability, style) inner_combine_linter (tags: consistency, efficiency, readability) is_numeric_linter (tags: best_practices, consistency, readability) lengths_linter (tags: best_practices, efficiency, readability) line_length_linter (tags: configurable, default, readability, style) literal_coercion_linter (tags: best_practices, consistency, efficiency) matrix_apply_linter (tags: efficiency, readability) missing_argument_linter (tags: common_mistakes, configurable, correctness) missing_package_linter (tags: common_mistakes, robustness) namespace_linter (tags: configurable, correctness, executing, robustness) nested_ifelse_linter (tags: efficiency, readability) nonportable_path_linter (tags: best_practices, configurable, robustness) numeric_leading_zero_linter (tags: consistency, readability, style) object_length_linter (tags: configurable, default, executing, readability, style) object_name_linter (tags: configurable, consistency, default, executing, style) object_usage_linter (tags: configurable, correctness, default, executing, readability, style) outer_negation_linter (tags: best_practices, efficiency, readability) package_hooks_linter (tags: correctness, package_development, style) paren_body_linter (tags: default, readability, style) paste_linter (tags: best_practices, configurable, consistency) pipe_call_linter (tags: readability, style) pipe_continuation_linter (tags: default, readability, style) quotes_linter (tags: configurable, consistency, default, readability, style) redundant_equals_linter (tags: best_practices, common_mistakes, efficiency, readability) redundant_ifelse_linter (tags: best_practices, configurable, consistency, efficiency) regex_subset_linter (tags: best_practices, efficiency) routine_registration_linter (tags: best_practices, efficiency, robustness) semicolon_linter (tags: configurable, default, readability, style) seq_linter (tags: best_practices, consistency, default, efficiency, robustness) sort_linter (tags: best_practices, efficiency, readability) spaces_inside_linter (tags: default, readability, style) spaces_left_parentheses_linter (tags: default, readability, style) sprintf_linter (tags: common_mistakes, correctness) string_boundary_linter (tags: configurable, efficiency, readability) strings_as_factors_linter (tags: robustness) system_file_linter (tags: best_practices, consistency, readability) T_and_F_symbol_linter (tags: best_practices, consistency, default, readability, robustness, style) todo_comment_linter (tags: configurable, style) trailing_blank_lines_linter (tags: default, style) trailing_whitespace_linter (tags: configurable, default, style) undesirable_function_linter (tags: best_practices, configurable, efficiency, robustness, style) undesirable_operator_linter (tags: best_practices, configurable, efficiency, robustness, style) unnecessary_concatenation_linter (tags: configurable, efficiency, readability, style) unnecessary_lambda_linter (tags: best_practices, efficiency, readability) unnecessary_nested_if_linter (tags: best_practices, readability) unnecessary_placeholder_linter (tags: best_practices, readability) unreachable_code_linter (tags: best_practices, readability) unused_import_linter (tags: best_practices, common_mistakes, configurable, executing) vector_logic_linter (tags: best_practices, default, efficiency) whitespace_linter (tags: consistency, default, style) yoda_test_linter (tags: best_practices, package_development, readability)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on defaults — linters_with_defaults","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"Make new list based lintr's default linters. result function meant passed linters argument lint(), put configuration file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"","code":"linters_with_defaults(..., defaults = default_linters) with_defaults(..., default = default_linters)"},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed. defaults, default Default list linters modify. Must named.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"","code":"# When using interactively you will usually pass the result onto `lint` or `lint_package()` f <- withr::local_tempfile(lines = \"my_slightly_long_variable_name <- 2.3\", fileext = \"R\") lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120))) #> Warning: cannot open file '/tmp/RtmpyuoqE0/file169075a66c88R': No such file or directory #> Error in file(con, \"r\"): cannot open the connection # the default linter list with a different line length cutoff my_linters <- linters_with_defaults(line_length_linter = line_length_linter(120)) # omit the argument name if you are just using different arguments my_linters <- linters_with_defaults(defaults = my_linters, object_name_linter(\"camelCase\")) # remove assignment checks (with NULL), add absolute path checks my_linters <- linters_with_defaults( defaults = my_linters, assignment_linter = NULL, absolute_path_linter() ) # checking the included linters names(my_linters) #> [1] \"absolute_path_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"cyclocomp_linter\" \"equals_na_linter\" #> [7] \"function_left_parentheses_linter\" \"indentation_linter\" #> [9] \"infix_spaces_linter\" \"line_length_linter\" #> [11] \"object_length_linter\" \"object_name_linter\" #> [13] \"object_usage_linter\" \"paren_body_linter\" #> [15] \"pipe_continuation_linter\" \"quotes_linter\" #> [17] \"semicolon_linter\" \"seq_linter\" #> [19] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [21] \"T_and_F_symbol_linter\" \"trailing_blank_lines_linter\" #> [23] \"trailing_whitespace_linter\" \"vector_logic_linter\" #> [25] \"whitespace_linter\""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a tag-based linter configuration — linters_with_tags","title":"Create a tag-based linter configuration — linters_with_tags","text":"Make new list based linters provided packages tagged tags. result function meant passed linters argument lint(), put configuration file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a tag-based linter configuration — linters_with_tags","text":"","code":"linters_with_tags(tags, ..., packages = \"lintr\", exclude_tags = \"deprecated\")"},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a tag-based linter configuration — linters_with_tags","text":"tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. ... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed. packages character vector packages search linters. exclude_tags Tags exclude results. Linters least one matching tag returned. except_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a tag-based linter configuration — linters_with_tags","text":"modified list linters.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a tag-based linter configuration — linters_with_tags","text":"","code":"# `linters_with_defaults()` and `linters_with_tags(\"default\")` are the same: all.equal(linters_with_defaults(), linters_with_tags(\"default\")) #> [1] TRUE # Get all linters useful for package development linters <- linters_with_tags(tags = c(\"package_development\", \"style\")) names(linters) #> [1] \"assignment_linter\" \"backport_linter\" #> [3] \"brace_linter\" \"commas_linter\" #> [5] \"commented_code_linter\" \"conjunct_test_linter\" #> [7] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [9] \"expect_comparison_linter\" \"expect_identical_linter\" #> [11] \"expect_length_linter\" \"expect_named_linter\" #> [13] \"expect_not_linter\" \"expect_null_linter\" #> [15] \"expect_s3_class_linter\" \"expect_s4_class_linter\" #> [17] \"expect_true_false_linter\" \"expect_type_linter\" #> [19] \"extraction_operator_linter\" \"function_argument_linter\" #> [21] \"function_left_parentheses_linter\" \"implicit_assignment_linter\" #> [23] \"implicit_integer_linter\" \"indentation_linter\" #> [25] \"infix_spaces_linter\" \"line_length_linter\" #> [27] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [29] \"object_name_linter\" \"object_usage_linter\" #> [31] \"package_hooks_linter\" \"paren_body_linter\" #> [33] \"pipe_call_linter\" \"pipe_continuation_linter\" #> [35] \"quotes_linter\" \"semicolon_linter\" #> [37] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [39] \"T_and_F_symbol_linter\" \"todo_comment_linter\" #> [41] \"trailing_blank_lines_linter\" \"trailing_whitespace_linter\" #> [43] \"undesirable_function_linter\" \"undesirable_operator_linter\" #> [45] \"unnecessary_concatenation_linter\" \"whitespace_linter\" #> [47] \"yoda_test_linter\" # Get all linters tagged as \"default\" from lintr and mypkg if (FALSE) { linters_with_tags(\"default\", packages = c(\"lintr\", \"mypkg\")) }"},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated functions in lintr — lintr-deprecated","title":"Deprecated functions in lintr — lintr-deprecated","text":"functions deprecated lintr. open_curly_linter() closed_curly_linter() check open closed curly braces line unless follow else, comma, closing bracket. Deprecated favor brace_linter(). paren_brace_linter() checks space right parentheses opening curly brace. E.g., function(){} space, function() {} . Deprecated favor brace_linter(). semicolon_terminator_linter() checks semicolons terminate expressions. Deprecated favor semicolon_linter().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deprecated functions in lintr — lintr-deprecated","text":"","code":"closed_curly_linter(allow_single_line = FALSE) open_curly_linter(allow_single_line = FALSE) paren_brace_linter() semicolon_terminator_linter(semicolon = c(\"compound\", \"trailing\")) unneeded_concatenation_linter(allow_single_expression = TRUE) single_quotes_linter() consecutive_stopifnot_linter() no_tab_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deprecated functions in lintr — lintr-deprecated","text":"allow_single_line TRUE, allow open closed curly pair line. semicolon character vector defining semicolons report: compound Semicolons separate two statements line. trailing Semicolons following last statement line.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Deprecated functions in lintr — lintr-deprecated","text":"configurable, deprecated, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lintr-package.html","id":null,"dir":"Reference","previous_headings":"","what":"Lintr — lintr-package","title":"Lintr — lintr-package","text":"Checks adherence given style, syntax errors, possible semantic issues. Supports fly checking R code edited Emacs, Vim, Sublime Text.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lintr-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Lintr — lintr-package","text":"Maintainer: Jim Hester james.f.hester@gmail.com Authors: Florent Angly (fangly) Russ Hyde Michael Chirico Kun Ren Alexander Rosenstock (AshesITR) Indrajeet Patil patilindrajeet.science@gmail.com (ORCID) (@patilindrajeets)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":".integer(1) (rlang::int(1)) 1L latter concise gets typed correctly compilation.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"","code":"literal_coercion_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"applies missing sentinels like NA -- typically, necessary specify storage type NA, , prefer using typed version (e.g. NA_real_) instead coercion (like .numeric(NA)).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"best_practices, consistency, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"","code":"# will produce lints lint( text = \"int(1)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use 1L instead of int(1), i.e., use literals directly where possible, instead of coercion. lint( text = \"as.character(NA)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use NA_character_ instead of as.character(NA), i.e., use literals directly where possible, instead of coercion. lint( text = \"rlang::lgl(1L)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use TRUE instead of rlang::lgl(1L), i.e., use literals directly where possible, instead of coercion. # okay lint( text = \"1L\", linters = literal_coercion_linter() ) lint( text = \"NA_character_\", linters = literal_coercion_linter() ) lint( text = \"TRUE\", linters = literal_coercion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"colSums() rowSums() clearer performant alternatives apply(x, 2, sum) apply(x, 1, sum) respectively case 2D arrays, matrices","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"matrix_apply_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"# will produce lints lint( text = \"apply(x, 1, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(x) rather than apply(x, 1, sum) lint( text = \"apply(x, 2, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x)) or colSums(x) if x has 2 dimensions rather than apply(x, 2, sum) lint( text = \"apply(x, 2, sum, na.rm = TRUE)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x, na.rm = TRUE)) or colSums(x, na.rm = TRUE) if x has 2 dimensions rather than apply(x, 2, sum, na.rm = TRUE) lint( text = \"apply(x, 2:4, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x), dims = 3) or colSums(x) if x has 4 dimensions rather than apply(x, 2:4, sum)"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing argument linter — missing_argument_linter","title":"Missing argument linter — missing_argument_linter","text":"Check missing arguments function calls (e.g. stats::median(1:10, )).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing argument linter — missing_argument_linter","text":"","code":"missing_argument_linter( except = c(\"alist\", \"quote\", \"switch\"), allow_trailing = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Missing argument linter — missing_argument_linter","text":"except character vector function names exceptions. allow_trailing always allow trailing empty arguments?","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing argument linter — missing_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing argument linter — missing_argument_linter","text":"","code":"# will produce lints lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter() ) #> ::warning file=,line=1,col=15::file=,line=1,col=15,[missing_argument_linter] Missing argument in function call. # okay lint( text = 'tibble(x = \"a\")', linters = missing_argument_linter() ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(except = \"tibble\") ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(allow_trailing = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing package linter — missing_package_linter","title":"Missing package linter — missing_package_linter","text":"Check missing packages library(), require(), loadNamespace(), requireNamespace() calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing package linter — missing_package_linter","text":"","code":"missing_package_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing package linter — missing_package_linter","text":"common_mistakes, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing package linter — missing_package_linter","text":"","code":"# will produce lints lint( text = \"library(xyzxyz)\", linters = missing_package_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[missing_package_linter] Package 'xyzxyz' is not installed. # okay lint( text = \"library(stats)\", linters = missing_package_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify lintr defaults — modify_defaults","title":"Modify lintr defaults — modify_defaults","text":"Modify list defaults name, allowing replacement, deletion addition new elements.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify lintr defaults — modify_defaults","text":"","code":"modify_defaults(defaults, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify lintr defaults — modify_defaults","text":"defaults named list elements modify. ... arguments elements change. unnamed, argument automatically named. named argument already exists defaults, replaced new element. exist, added. value NULL, element removed.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify lintr defaults — modify_defaults","text":"modified list elements, sorted name. achieve sort platform-independent way, two transformations applied names: (1) replace _ 0 (2) convert tolower().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Modify lintr defaults — modify_defaults","text":"","code":"# custom list of undesirable functions: # remove `sapply` (using `NULL`) # add `cat` (with an accompanying message), # add `print` (unnamed, i.e. with no accompanying message) # add `source` (as taken from `all_undesirable_functions`) my_undesirable_functions <- modify_defaults( defaults = default_undesirable_functions, sapply = NULL, \"cat\" = \"No cat allowed\", \"print\", all_undesirable_functions[[\"source\"]] ) # list names of functions specified as undesirable names(my_undesirable_functions) #> [1] \".libPaths\" \"attach\" \"browser\" \"cat\" #> [5] \"debug\" \"debugcall\" \"debugonce\" \"detach\" #> [9] \"library\" \"mapply\" \"options\" \"par\" #> [13] \"print\" \"require\" \"setwd\" \"sink\" #> [17] \"source\" \"Sys.setenv\" \"Sys.setlocale\" \"trace\" #> [21] \"undebug\" \"untrace\""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Namespace linter — namespace_linter","title":"Namespace linter — namespace_linter","text":"Check missing packages symbols namespace calls. Note using check_exports=TRUE check_nonexports=TRUE load packages used user code potentially change global state.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Namespace linter — namespace_linter","text":"","code":"namespace_linter(check_exports = TRUE, check_nonexports = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Namespace linter — namespace_linter","text":"check_exports Check symbol exported namespace namespace::symbol calls. check_nonexports Check symbol exists namespace namespace:::symbol calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Namespace linter — namespace_linter","text":"configurable, correctness, executing, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Namespace linter — namespace_linter","text":"","code":"# will produce lints lint( text = \"xyzxyz::sd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[namespace_linter] Package 'xyzxyz' is not installed. lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[namespace_linter] 'ssd' is not exported from {stats}. # okay lint( text = \"stats::sd(c(1, 2, 3))\", linters = namespace_linter() ) lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter(check_exports = FALSE) ) lint( text = \"stats:::ssd(c(1, 2, 3))\", linters = namespace_linter(check_nonexports = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of nested ifelse() calls — nested_ifelse_linter","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Calling ifelse() nested calls problematic two main reasons: can hard read -- mapping code expected output code can messy task/require lot mental bandwidth, especially code nests inefficient -- ifelse() can evaluate arguments yes (see https://stackoverflow.com/q/16275149); issue exacerbated nested calls","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"nested_ifelse_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Users can instead rely readable alternative modeled SQL CASE statements, data.table::fcase() dplyr::case_when(), use look---merge approach (build mapping table values outputs merge input).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"# will produce lints lint( text = 'ifelse(x == \"a\", 1L, ifelse(x == \"b\", 2L, 3L))', linters = nested_ifelse_linter() ) #> ::warning file=,line=1,col=22::file=,line=1,col=22,[nested_ifelse_linter] Don't use nested ifelse() calls; instead, try (1) data.table::fcase; (2) dplyr::case_when; or (3) using a lookup table. # okay lint( text = 'dplyr::case_when(x == \"a\" ~ 1L, x == \"b\" ~ 2L, TRUE ~ 3L)', linters = nested_ifelse_linter() ) lint( text = 'data.table::fcase(x == \"a\", 1L, x == \"b\", 2L, default = 3L)', linters = nested_ifelse_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Non-portable path linter — nonportable_path_linter","title":"Non-portable path linter — nonportable_path_linter","text":"Check file.path() used construct safe portable paths.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Non-portable path linter — nonportable_path_linter","text":"","code":"nonportable_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Non-portable path linter — nonportable_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Non-portable path linter — nonportable_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":null,"dir":"Reference","previous_headings":"","what":"Normalize lint exclusions — normalize_exclusions","title":"Normalize lint exclusions — normalize_exclusions","text":"Normalize lint exclusions","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Normalize lint exclusions — normalize_exclusions","text":"","code":"normalize_exclusions(x, normalize_path = TRUE, root = getwd(), pattern = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Normalize lint exclusions — normalize_exclusions","text":"x Exclusion specification character vector filenames directories relative root named list integers specifying lines excluded per file named list named lists specifying linters lines excluded linters per file. normalize_path names returned exclusion list normalized paths? , relative root. root Base directory relative filename resolution. pattern non-NULL, exclude files excluded directories match pattern. Passed list.files directory excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Normalize lint exclusions — normalize_exclusions","text":"named list file exclusions. names list specify filenames excluded. file exclusion possibly named list containing line numbers exclude, sentinel Inf completely excluded files. entry named, exclusions take effect linter name. normalize_path TRUE, file names normalized relative root. Otherwise paths left provided (relative root absolute).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":".1 0.1 mean thing, latter easier read due small size '.' glyph.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"","code":"numeric_leading_zero_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"","code":"# will produce lints lint( text = \"x <- .1\", linters = numeric_leading_zero_linter() ) #> ::warning file=,line=1,col=6::file=