diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index 673e41176..6292436e3 100644 --- a/dev/pkgdown.yml +++ b/dev/pkgdown.yml @@ -6,7 +6,7 @@ articles: creating_linters: creating_linters.html editors: editors.html lintr: lintr.html -last_built: 2024-07-18T20:42Z +last_built: 2024-07-24T09:02Z urls: reference: https://lintr.r-lib.org/reference article: https://lintr.r-lib.org/articles diff --git a/dev/reference/get_source_expressions.html b/dev/reference/get_source_expressions.html index 9a24694e4..f54e6a7ca 100644 --- a/dev/reference/get_source_expressions.html +++ b/dev/reference/get_source_expressions.html @@ -130,7 +130,7 @@
f <- tempfile()
writeLines("a=1", f)
lint(f) # linting a file
-#> /tmp/RtmpVnxWsC/file173b1162aca6:1:2: style: [assignment_linter] Use <-, not =, for assignment.
+#> /tmp/Rtmpg3LDxu/file16b957e8c6e6:1:2: style: [assignment_linter] Use <-, not =, for assignment.
#> a=1
#> ^
-#> /tmp/RtmpVnxWsC/file173b1162aca6:1:2: style: [infix_spaces_linter] Put spaces around all infix operators.
+#> /tmp/Rtmpg3LDxu/file16b957e8c6e6:1:2: style: [infix_spaces_linter] Put spaces around all infix operators.
#> a=1
#> ^
lint("a = 123\n") # linting inline-code
diff --git a/dev/reference/read_settings.html b/dev/reference/read_settings.html
index b6450873e..592c3291e 100644
--- a/dev/reference/read_settings.html
+++ b/dev/reference/read_settings.html
@@ -97,7 +97,21 @@ Details
or the environment variable R_LINTR_LINTER_FILE
This file is a DCF file, see base::read.dcf()
for details.
Here is an example of a .lintr
file:
-
+linters: linters_with_defaults(
+ any_duplicated_linter(),
+ any_is_na_linter(),
+ backport_linter("oldrel-4", except = c("R_user_dir", "str2lang")),
+ line_length_linter(120L),
+ missing_argument_linter(),
+ unnecessary_concatenation_linter(allow_single_expression = FALSE),
+ yoda_test_linter()
+ )
+exclusions: list(
+ "inst/doc/creating_linters.R" = 1,
+ "inst/example/bad.R",
+ "tests/testthat/default_linter_testcode.R",
+ "tests/testthat/dummy_packages"
+ )
Experimentally, we also support keeping the config in a plain R file. By default we look for
a file named .lintr.R
(in the same directories where we search for .lintr
).
We are still deciding the future of config support in lintr, so user feedback is welcome.
diff --git a/dev/reference/trailing_blank_lines_linter.html b/dev/reference/trailing_blank_lines_linter.html
index 55dc17dca..e5bd2e5f2 100644
--- a/dev/reference/trailing_blank_lines_linter.html
+++ b/dev/reference/trailing_blank_lines_linter.html
@@ -83,7 +83,7 @@
Examples filename = f,
linters = trailing_blank_lines_linter()
)
-#> /tmp/RtmpVnxWsC/file173b339595e7:2:1: style: [trailing_blank_lines_linter] Remove trailing blank lines.
+#> /tmp/Rtmpg3LDxu/file16b97d1fff80:2:1: style: [trailing_blank_lines_linter] Remove trailing blank lines.
#>
#> ^
unlink(f)
diff --git a/dev/search.json b/dev/search.json
index 97a0b71b8..1452df3e0 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 michaelchirico4@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":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"for-packages","dir":"Articles","previous_headings":"","what":"For packages","title":"Continuous integration","text":"First, take special note proviso ?executing_linters need package dependencies installed loaded (e.g. pkgload::load_all()) order certain linters (e.g. object_usage_linter()) function intended.","code":""},{"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":"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. Note check unnecessary provided linter_level = \"expression\" guarantees source_expression expression level file level. 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. efficient way implement condition (!is_lint_level(source_expression, \"expression\")).","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\" ) linter_level = \"expression\""},{"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_no_lint(\"blah\", 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. xml_find_function_calls(): Whenever linter needs query R function calls, e.g. via XPath //SYMBOL_FUNCTION_CALL[text() = 'myfun'], use member source_expression obtain function call nodes efficiently. Instead use make_linter_from_xpath() make_linter_from_function_xpath(): Whenever linter can expressed static XPath static message, use make_linter_from_xpath() , XPath starts //SYMBOL_FUNCTION_CALL, use make_linter_from_function_xpath(). Instead make_linter_from_xpath(xpath = \"//SYMBOL_FUNCTION_CALL[text() = 'foo' text() = 'bar']/cond\"), use make_linter_from_function_xpath(function_names = c(\"foo\", \"bar\"), xpath = \"cond\").","code":"xml <- source_expression$xml_parsed_content xpath <- \"//SYMBOL_FUNCTION_CALL[text() = 'myfun']/parent::expr/some/cond\" xml_find_all(xml, xpath) xml_calls <- source_expression$xml_find_function_calls(\"myfun\") call_xpath <- \"parent::expr/some/cond\" xml_find_all(xml_calls, call_xpath)"},{"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). 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.","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.","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.","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.","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. Note linters (e.g. object_usage_linter()) require package installed function properly. pkgload::load_all() also suffice. See ?executing_linters details.","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\" \"pkg_testthat\" \"readability\" #> [13] \"regex\" \"robustness\" \"style\" #> [16] \"tidy_design\" 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\" \"comparison_negation_linter\" #> [7] \"conjunct_test_linter\" \"consecutive_assertion_linter\" #> [9] \"consecutive_mutate_linter\" \"cyclocomp_linter\" #> [11] \"empty_assignment_linter\" \"expect_comparison_linter\" #> [13] \"expect_identical_linter\" \"expect_length_linter\" #> [15] \"expect_named_linter\" \"expect_not_linter\" #> [17] \"expect_null_linter\" \"expect_s3_class_linter\" #> [19] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [21] \"expect_type_linter\" \"fixed_regex_linter\" #> [23] \"for_loop_index_linter\" \"function_left_parentheses_linter\" #> [25] \"function_return_linter\" \"if_not_else_linter\" #> [27] \"if_switch_linter\" \"implicit_assignment_linter\" #> [29] \"indentation_linter\" \"infix_spaces_linter\" #> [31] \"inner_combine_linter\" \"is_numeric_linter\" #> [33] \"keyword_quote_linter\" \"length_levels_linter\" #> [35] \"lengths_linter\" \"library_call_linter\" #> [37] \"line_length_linter\" \"matrix_apply_linter\" #> [39] \"nested_ifelse_linter\" \"nested_pipe_linter\" #> [41] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [43] \"object_overwrite_linter\" \"object_usage_linter\" #> [45] \"one_call_pipe_linter\" \"outer_negation_linter\" #> [47] \"package_hooks_linter\" \"paren_body_linter\" #> [49] \"pipe_call_linter\" \"pipe_consistency_linter\" #> [51] \"pipe_continuation_linter\" \"quotes_linter\" #> [53] \"redundant_equals_linter\" \"rep_len_linter\" #> [55] \"repeat_linter\" \"sample_int_linter\" #> [57] \"scalar_in_linter\" \"semicolon_linter\" #> [59] \"sort_linter\" \"spaces_inside_linter\" #> [61] \"spaces_left_parentheses_linter\" \"stopifnot_all_linter\" #> [63] \"string_boundary_linter\" \"system_file_linter\" #> [65] \"T_and_F_symbol_linter\" \"unnecessary_concatenation_linter\" #> [67] \"unnecessary_lambda_linter\" \"unnecessary_nesting_linter\" #> [69] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [71] \"which_grepl_linter\" \"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] \"comparison_negation_linter\" \"condition_call_linter\" #> [13] \"condition_message_linter\" \"conjunct_test_linter\" #> [15] \"consecutive_assertion_linter\" \"consecutive_mutate_linter\" #> [17] \"cyclocomp_linter\" \"duplicate_argument_linter\" #> [19] \"empty_assignment_linter\" \"equals_na_linter\" #> [21] \"expect_comparison_linter\" \"expect_identical_linter\" #> [23] \"expect_length_linter\" \"expect_named_linter\" #> [25] \"expect_not_linter\" \"expect_null_linter\" #> [27] \"expect_s3_class_linter\" \"expect_s4_class_linter\" #> [29] \"expect_true_false_linter\" \"expect_type_linter\" #> [31] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [33] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [35] \"function_return_linter\" \"if_not_else_linter\" #> [37] \"if_switch_linter\" \"ifelse_censor_linter\" #> [39] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [41] \"indentation_linter\" \"infix_spaces_linter\" #> [43] \"inner_combine_linter\" \"is_numeric_linter\" #> [45] \"keyword_quote_linter\" \"length_levels_linter\" #> [47] \"length_test_linter\" \"lengths_linter\" #> [49] \"library_call_linter\" \"line_length_linter\" #> [51] \"list_comparison_linter\" \"literal_coercion_linter\" #> [53] \"matrix_apply_linter\" \"missing_argument_linter\" #> [55] \"missing_package_linter\" \"namespace_linter\" #> [57] \"nested_ifelse_linter\" \"nested_pipe_linter\" #> [59] \"nonportable_path_linter\" \"nrow_subset_linter\" #> [61] \"numeric_leading_zero_linter\" \"nzchar_linter\" #> [63] \"object_length_linter\" \"object_name_linter\" #> [65] \"object_overwrite_linter\" \"object_usage_linter\" #> [67] \"one_call_pipe_linter\" \"outer_negation_linter\" #> [69] \"package_hooks_linter\" \"paren_body_linter\" #> [71] \"paste_linter\" \"pipe_call_linter\" #> [73] \"pipe_consistency_linter\" \"pipe_continuation_linter\" #> [75] \"pipe_return_linter\" \"print_linter\" #> [77] \"quotes_linter\" \"redundant_equals_linter\" #> [79] \"redundant_ifelse_linter\" \"regex_subset_linter\" #> [81] \"rep_len_linter\" \"repeat_linter\" #> [83] \"return_linter\" \"routine_registration_linter\" #> [85] \"sample_int_linter\" \"scalar_in_linter\" #> [87] \"semicolon_linter\" \"seq_linter\" #> [89] \"sort_linter\" \"spaces_inside_linter\" #> [91] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [93] \"stopifnot_all_linter\" \"string_boundary_linter\" #> [95] \"strings_as_factors_linter\" \"system_file_linter\" #> [97] \"T_and_F_symbol_linter\" \"terminal_close_linter\" #> [99] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [101] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [103] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [105] \"unnecessary_lambda_linter\" \"unnecessary_nesting_linter\" #> [107] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [109] \"unused_import_linter\" \"vector_logic_linter\" #> [111] \"which_grepl_linter\" \"whitespace_linter\" #> [113] \"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) linter_name <- \"assignment_linter\" show_lint <- function(l) { lint_df <- as.data.frame(l) print(lint_df[, c(\"line_number\", \"message\", \"linter\")]) } hline <- function() cat(strrep(\"-\", getOption(\"width\") - 5L), \"\\n\", sep = \"\") withr::with_tempfile(\"tmp\", { writeLines(\"a = 1\", tmp) # linter column is just 'get' show_lint(lint(tmp, linters = get(linter_name)())) hline() this_linter <- get(linter_name)() attr(this_linter, \"name\") <- linter_name # linter column is 'assignment_linter' show_lint(lint(tmp, linters = this_linter)) hline() # more concise alternative for this case: use eval(call(.)) show_lint(lint(tmp, linters = eval(call(linter_name)))) }) #> line_number message linter #> 1 1 Use <-, not =, for assignment. get #> --------------------------------------------------------------------------- #> line_number message linter #> 1 1 Use <-, not =, for assignment. assignment_linter #> --------------------------------------------------------------------------- #> line_number message linter #> 1 1 Use <-, not =, for assignment. 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. #> :1:1: style: [object_name_linter] Variable and function name style should match snake_case or symbols. #> X = 42L # -------------- this comment overflows the default 80 chars line length. #> ^ #> :1:3: style: [assignment_linter] Use <-, not =, for assignment. #> X = 42L # -------------- this comment overflows the default 80 chars line length. #> ^ #> :1:81: style: [line_length_linter] Lines should not be more than 80 characters. This line is 81 characters. #> X = 42L # -------------- this comment overflows the default 80 chars line length. #> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 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. #> :1:3: style: [assignment_linter] Use <-, not =, for assignment. #> X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ^ #> :1:81: style: [line_length_linter] Lines should not be more than 80 characters. This line is 94 characters. #> X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> :1:3: style: [assignment_linter] Use <-, not =, for assignment. #> X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> ^ X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> :1:3: style: [assignment_linter] Use <-, not =, for assignment. #> X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> ^"},{"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) #> :1:3: style: [commented_code_linter] Remove commented code. #> # x <- 42L #> ^~~~~~~~ #> :2:3: style: [commented_code_linter] Remove commented code. #> # print(x) #> ^~~~~~~~ # 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. Florent Angly. Author. fangly Russ Hyde. Author. Michael Chirico. Author, maintainer. 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 (2024). lintr: 'Linter' R Code. R package version 3.1.2.9000, 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 = {2024}, note = {R package version 3.1.2.9000, https://github.com/r-lib/lintr}, url = {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(), linter_level = c(NA_character_, \"file\", \"expression\") )"},{"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. linter_level level expression linter working ? \"expression\" means individual expression xml_parsed_content, \"file\" means expressions current file available full_xml_parsed_content. NA means linter run , expression-level file-level source expressions.","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":"Although can synonyms, avoid symbols T F, use TRUE FALSE, respectively, instead. T F reserved keywords can assigned values.","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() ) #> :1:7: style: [T_and_F_symbol_linter] Use TRUE instead of the symbol T. #> x <- T; y <- F #> ~^ #> :1:15: style: [T_and_F_symbol_linter] Use FALSE instead of the symbol F. #> x <- T; y <- F #> ~^ lint( text = \"T = 1.2; F = 2.4\", linters = T_and_F_symbol_linter() ) #> :1:2: style: [T_and_F_symbol_linter] Don't use T as a variable name, as it can break code relying on T being TRUE. #> T = 1.2; F = 2.4 #> ~^ #> :1:11: style: [T_and_F_symbol_linter] Don't use F as a variable name, as it can break code relying on F being FALSE. #> T = 1.2; F = 2.4 #> ~^ # 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":"# will produce lints lint( text = 'R\"--[/blah/file.txt]--\"', linters = absolute_path_linter() ) #> :1:2: warning: [absolute_path_linter] Do not use absolute paths. #> R\"--[/blah/file.txt]--\" #> ^~~~~~~~~~~~~~~~~~~~~ # 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":"... 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.","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] \"comparison_negation_linter\" \"condition_call_linter\" #> [13] \"condition_message_linter\" \"conjunct_test_linter\" #> [15] \"consecutive_assertion_linter\" \"consecutive_mutate_linter\" #> [17] \"cyclocomp_linter\" \"duplicate_argument_linter\" #> [19] \"empty_assignment_linter\" \"equals_na_linter\" #> [21] \"expect_comparison_linter\" \"expect_identical_linter\" #> [23] \"expect_length_linter\" \"expect_named_linter\" #> [25] \"expect_not_linter\" \"expect_null_linter\" #> [27] \"expect_s3_class_linter\" \"expect_s4_class_linter\" #> [29] \"expect_true_false_linter\" \"expect_type_linter\" #> [31] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [33] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [35] \"function_return_linter\" \"if_not_else_linter\" #> [37] \"if_switch_linter\" \"ifelse_censor_linter\" #> [39] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [41] \"indentation_linter\" \"infix_spaces_linter\" #> [43] \"inner_combine_linter\" \"is_numeric_linter\" #> [45] \"keyword_quote_linter\" \"length_levels_linter\" #> [47] \"length_test_linter\" \"lengths_linter\" #> [49] \"library_call_linter\" \"line_length_linter\" #> [51] \"list_comparison_linter\" \"literal_coercion_linter\" #> [53] \"matrix_apply_linter\" \"missing_argument_linter\" #> [55] \"missing_package_linter\" \"namespace_linter\" #> [57] \"nested_ifelse_linter\" \"nested_pipe_linter\" #> [59] \"nonportable_path_linter\" \"nrow_subset_linter\" #> [61] \"numeric_leading_zero_linter\" \"nzchar_linter\" #> [63] \"object_length_linter\" \"object_name_linter\" #> [65] \"object_overwrite_linter\" \"object_usage_linter\" #> [67] \"one_call_pipe_linter\" \"outer_negation_linter\" #> [69] \"package_hooks_linter\" \"paren_body_linter\" #> [71] \"paste_linter\" \"pipe_call_linter\" #> [73] \"pipe_consistency_linter\" \"pipe_continuation_linter\" #> [75] \"pipe_return_linter\" \"print_linter\" #> [77] \"quotes_linter\" \"redundant_equals_linter\" #> [79] \"redundant_ifelse_linter\" \"regex_subset_linter\" #> [81] \"rep_len_linter\" \"repeat_linter\" #> [83] \"return_linter\" \"routine_registration_linter\" #> [85] \"sample_int_linter\" \"scalar_in_linter\" #> [87] \"semicolon_linter\" \"seq_linter\" #> [89] \"sort_linter\" \"spaces_inside_linter\" #> [91] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [93] \"stopifnot_all_linter\" \"string_boundary_linter\" #> [95] \"strings_as_factors_linter\" \"system_file_linter\" #> [97] \"T_and_F_symbol_linter\" \"terminal_close_linter\" #> [99] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [101] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [103] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [105] \"unnecessary_lambda_linter\" \"unnecessary_nesting_linter\" #> [107] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [109] \"unused_import_linter\" \"vector_logic_linter\" #> [111] \"which_grepl_linter\" \"whitespace_linter\" #> [113] \"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() ) #> :1:1: warning: [any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). #> any(duplicated(x), na.rm = TRUE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"length(unique(x)) == length(x)\", linters = any_duplicated_linter() ) #> :1:1: warning: [any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). #> 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() ) #> :1:1: warning: [any_is_na_linter] anyNA(x) is better than any(is.na(x)). #> any(is.na(x), na.rm = TRUE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"any(is.na(foo(x)))\", linters = any_is_na_linter() ) #> :1:1: warning: [any_is_na_linter] anyNA(x) is better than any(is.na(x)). #> any(is.na(foo(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() ) #> :1:3: style: [assignment_linter] Use <-, not =, for assignment. #> x = mean(x) #> ^ code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter() ) #> :1:3: style: [assignment_linter] Use <-, not ->, for assignment. #> 1 -> x #> ^~ #> :2:3: style: [assignment_linter] Replace ->> by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. #> 2 ->> y #> ^~~ lint( text = \"x %<>% as.character()\", linters = assignment_linter() ) #> :1:3: style: [assignment_linter] Avoid the assignment pipe %<>%; prefer using <- and %>% separately. #> x %<>% as.character() #> ^~~~ # 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) ) #> :1:3: style: [assignment_linter] Replace <<- by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. #> x <<- 1 #> ^~~ writeLines(\"foo(bar = \\n 1)\") #> foo(bar = #> 1) lint( text = \"foo(bar = \\n 1)\", linters = assignment_linter(allow_trailing = FALSE) ) #> :1:9: style: [assignment_linter] Assignment = should not be trailing at the end of a line. #> foo(bar = #> ^ 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. exclude_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded. Note linters tag \"defunct\" (work can longer run) queried directly. See lintr-deprecated instead.","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\" \"pkg_testthat\" \"readability\" #> [13] \"regex\" \"robustness\" \"style\" #> [16] \"tidy_design\""},{"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\") ) #> :1:1: warning: [backport_linter] trimws (R 3.2.0) is not available for dependency R >= 3.0.0. #> trimws(x) #> ^~~~~~ lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\") ) #> :1:1: warning: [backport_linter] str2lang (R 3.6.0) is not available for dependency R >= 3.2.0. #> str2lang(x) #> ^~~~~~~~ # okay lint( text = \"trimws(x)\", linters = backport_linter(\"3.6.0\") ) lint( text = \"str2lang(x)\", linters = backport_linter(\"4.0.0\") ) lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\", except = \"str2lang\") )"},{"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_call_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 fixed_regex_linter for_loop_index_linter function_argument_linter function_return_linter if_switch_linter ifelse_censor_linter implicit_assignment_linter implicit_integer_linter is_numeric_linter length_levels_linter lengths_linter library_call_linter list_comparison_linter literal_coercion_linter nonportable_path_linter nrow_subset_linter nzchar_linter object_overwrite_linter outer_negation_linter paste_linter pipe_return_linter print_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter rep_len_linter routine_registration_linter scalar_in_linter seq_linter sort_linter stopifnot_all_linter system_file_linter T_and_F_symbol_linter terminal_close_linter undesirable_function_linter undesirable_operator_linter unnecessary_lambda_linter unnecessary_nesting_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() ) #> :1:1: warning: [boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). #> length(which(x == y)) == 0L #> ^~~~~~~~~~~~~~~~~~~~~ lint( text = \"sum(grepl(pattern, x)) == 0\", linters = boolean_arithmetic_linter() ) #> :1:1: warning: [boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). #> sum(grepl(pattern, x)) == 0 #> ^~~~~~~~~~~~~~~~~~~~~~ # 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() ) #> :1:17: style: [brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line. #> f <- function() { 1 } #> ^ #> :1:21: style: [brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. #> f <- function() { 1 } #> ^ writeLines(\"if (TRUE) {\\n return(1) }\") #> if (TRUE) { #> return(1) } lint( text = \"if (TRUE) {\\n return(1) }\", linters = brace_linter() ) #> :2:12: style: [brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. #> return(1) } #> ^ # 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() ) #> :1:10: warning: [class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with ==. #> is_lm <- class(x) == \"lm\" #> ^~~~~~~~~~~~~~~~ lint( text = 'if (\"lm\" %in% class(x)) is_lm <- TRUE', linters = class_equals_linter() ) #> :1:5: warning: [class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with %in%. #> if (\"lm\" %in% class(x)) is_lm <- TRUE #> ^~~~~~~~~~~~~~~~~~ # 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(allow_trailing = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Commas linter — commas_linter","text":"allow_trailing TRUE, linter allows comma followed directly closing bracket without space.","code":""},{"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":"configurable, 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() ) #> :1:10: style: [commas_linter] Remove spaces before a comma. #> switch(op , x = foo, y = bar) #> ^ lint( text = \"mean(x,trim = 0.2,na.rm = TRUE)\", linters = commas_linter() ) #> :1:8: style: [commas_linter] Put a space after a comma. #> mean(x,trim = 0.2,na.rm = TRUE) #> ^ #> :1:19: style: [commas_linter] Put a space after a comma. #> mean(x,trim = 0.2,na.rm = TRUE) #> ^ lint( text = \"x[ ,, drop=TRUE]\", linters = commas_linter() ) #> :1:3: style: [commas_linter] Remove spaces before a comma. #> x[ ,, drop=TRUE] #> ^ #> :1:5: style: [commas_linter] Put a space after a comma. #> x[ ,, drop=TRUE] #> ^ lint( text = \"x[1,]\", linters = commas_linter() ) #> :1:5: style: [commas_linter] Put a space after a comma. #> x[1,] #> ^ # 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() ) lint( text = \"x[1,]\", linters = commas_linter(allow_trailing = TRUE) )"},{"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() ) #> :1:3: style: [commented_code_linter] Remove commented code. #> # x <- 1 #> ^~~~~~ lint( text = \"x <- f() # g()\", linters = commented_code_linter() ) #> :1:12: style: [commented_code_linter] Remove commented code. #> x <- f() # g() #> ^~~ lint( text = \"x + y # + z[1, 2]\", linters = commented_code_linter() ) #> :1:9: style: [commented_code_linter] Remove commented code. #> x + y # + z[1, 2] #> ^~~~~~~~~ # 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 length_test_linter list_comparison_linter missing_argument_linter missing_package_linter pipe_return_linter redundant_equals_linter sprintf_linter unused_import_linter vector_logic_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"!(x == y) readably expressed x != y. true negations simple comparisons like !(x > y) !(x <= y).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"","code":"comparison_negation_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"","code":"# will produce lints lint( text = \"!x == 2\", linters = comparison_negation_linter() ) #> :1:1: warning: [comparison_negation_linter] Use x != y, not !(x == y). #> !x == 2 #> ^~~~~~~ lint( text = \"!(x > 2)\", linters = comparison_negation_linter() ) #> :1:1: warning: [comparison_negation_linter] Use x <= y, not !(x > y). #> !(x > 2) #> ^~~~~~~~ # okay lint( text = \"!(x == 2 & y > 2)\", linters = comparison_negation_linter() ) lint( text = \"!(x & y)\", linters = comparison_negation_linter() ) lint( text = \"x != 2\", linters = comparison_negation_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Recommend usage of call. = FALSE in conditions — condition_call_linter","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"linter, default display_call = FALSE, enforces recommendation tidyverse design guide regarding displaying error calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"","code":"condition_call_linter(display_call = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"display_call Logical specifying expected behavior regarding call. argument conditions. NA forces providing call. = ignores value (can used cases expect mix call. = FALSE call. = TRUE) TRUE lints call. = FALSE FALSE forces call. = FALSE (lints call. = TRUE missing call. = value)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"best_practices, configurable, style, tidy_design","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"","code":"# will produce lints lint( text = \"stop('test')\", linters = condition_call_linter() ) #> :1:1: warning: [condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. #> stop('test') #> ^~~~~~~~~~~~ lint( text = \"stop('test', call. = TRUE)\", linters = condition_call_linter() ) #> :1:1: warning: [condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. #> stop('test', call. = TRUE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"stop('test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> :1:1: warning: [condition_call_linter] Use stop(.) to display the call in an error message. #> stop('test', call. = FALSE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"stop('this is a', 'test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> :1:1: warning: [condition_call_linter] Use stop(.) to display the call in an error message. #> stop('this is a', 'test', call. = FALSE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = \"stop('test', call. = FALSE)\", linters = condition_call_linter() ) lint( text = \"stop('this is a', 'test', call. = FALSE)\", linters = condition_call_linter() ) lint( text = \"stop('test', call. = TRUE)\", linters = condition_call_linter(display_call = TRUE) )"},{"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(). 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":"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":[]},{"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() ) #> :1:1: warning: [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(). #> stop(paste(\"a string\", \"another\")) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'warning(paste0(\"a string\", \" another\"))', linters = condition_message_linter() ) #> :1:1: warning: [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(). #> warning(paste0(\"a string\", \" another\")) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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 commas_linter condition_call_linter conjunct_test_linter consecutive_mutate_linter cyclocomp_linter duplicate_argument_linter fixed_regex_linter if_not_else_linter if_switch_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter library_call_linter line_length_linter missing_argument_linter namespace_linter nested_pipe_linter nonportable_path_linter object_length_linter object_name_linter object_overwrite_linter object_usage_linter paste_linter pipe_consistency_linter quotes_linter redundant_ifelse_linter return_linter scalar_in_linter semicolon_linter string_boundary_linter todo_comment_linter trailing_whitespace_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unnecessary_lambda_linter unnecessary_nesting_linter unreachable_code_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 to be written separately where appropriate — conjunct_test_linter","title":"Force && conditions to be written separately where appropriate — 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 to be written separately where appropriate — conjunct_test_linter","text":"","code":"conjunct_test_linter( allow_named_stopifnot = TRUE, allow_filter = c(\"never\", \"not_dplyr\", \"always\") )"},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Force && conditions to be written separately where appropriate — 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. allow_filter Character naming method linting calls filter(). default, \"never\", means filter() dplyr::filter() calls linted; \"not_dplyr\" means dplyr::filter() calls linted; \"always\" means calls filter() linted. Calls like stats::filter() never 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 to be written separately where appropriate — conjunct_test_linter","text":"Similar reasoning applies && usage inside stopifnot() assertthat::assert_that() calls. Relatedly, dplyr::filter(DF, & B) dplyr::filter(DF, , B), latter readable / easier format long conditions. Note linter assumes usages filter() dplyr::filter(); using another function named filter(), e.g. stats::filter(), please namespace-qualify avoid false positives. can omit linting filter() expressions altogether via allow_filter = TRUE.","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 to be written separately where appropriate — conjunct_test_linter","text":"best_practices, configurable, package_development, pkg_testthat, 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 to be written separately where appropriate — conjunct_test_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x && y)\", linters = conjunct_test_linter() ) #> :1:1: warning: [conjunct_test_linter] Write multiple expectations like expect_true(A) and expect_true(B) instead of expect_true(A && B). The latter will produce better error messages in the case of failure. #> expect_true(x && y) #> ^~~~~~~~~~~~~~~~~~~ lint( text = \"expect_false(x || (y && z))\", linters = conjunct_test_linter() ) #> :1:1: warning: [conjunct_test_linter] Write multiple expectations like expect_false(A) and expect_false(B) instead of expect_false(A || B). The latter will produce better error messages in the case of failure. #> expect_false(x || (y && z)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 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) ) #> :1:1: warning: [conjunct_test_linter] Write multiple conditions like stopifnot(A, B) instead of stopifnot(A && B). The latter will produce better error messages in the case of failure. #> stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"dplyr::filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> :1:23: warning: [conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). #> dplyr::filter(mtcars, mpg > 20 & vs == 0) #> ^~~~~~~~~~~~~~~~~~ lint( text = \"filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> :1:16: warning: [conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). #> filter(mtcars, mpg > 20 & vs == 0) #> ^~~~~~~~~~~~~~~~~~ # 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) ) lint( text = \"dplyr::filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter(allow_filter = \"always\") ) lint( text = \"filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter(allow_filter = \"not_dplyr\") ) lint( text = \"stats::filter(mtcars$cyl, mtcars$mpg > 20 & mtcars$vs == 0)\", linters = conjunct_test_linter() )"},{"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() ) #> :1:1: warning: [consecutive_assertion_linter] Unify consecutive calls to stopifnot(). #> stopifnot(x); stopifnot(y) #> ^~~~~~~~~~~~ lint( text = \"assert_that(x); assert_that(y)\", linters = consecutive_assertion_linter() ) #> :1:1: warning: [consecutive_assertion_linter] Unify consecutive calls to assert_that(). #> assert_that(x); assert_that(y) #> ^~~~~~~~~~~~~~ # 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/consecutive_mutate_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"dplyr::mutate() accepts number columns, sequences like DF %>% dplyr::mutate(..1) %>% dplyr::mutate(..2) redundant – can always expressed single call dplyr::mutate().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"","code":"consecutive_mutate_linter(invalid_backends = \"dbplyr\")"},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"invalid_backends Character vector packages providing dplyr backends may compatible combining mutate() calls cases. Defaults \"dbplyr\" since SQL backends can handle re-using variable defined mutate() expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"exception SQL back-ends, translation logic may sophisticated default dplyr, example DF %>% mutate(= + 1) %>% mutate(b = - 2).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"configurable, consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"","code":"# will produce lints lint( text = \"x %>% mutate(a = 1) %>% mutate(b = 2)\", linters = consecutive_mutate_linter() ) #> :1:25: warning: [consecutive_mutate_linter] Unify consecutive calls to mutate(). #> x %>% mutate(a = 1) %>% mutate(b = 2) #> ^~~~~~~~~~~~~ # okay lint( text = \"x %>% mutate(a = 1, b = 2)\", linters = consecutive_mutate_linter() ) code <- \"library(dbplyr)\\nx %>% mutate(a = 1) %>% mutate(a = a + 1)\" writeLines(code) #> library(dbplyr) #> x %>% mutate(a = 1) %>% mutate(a = a + 1) lint( text = code, linters = consecutive_mutate_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 comparison_negation_linter condition_message_linter consecutive_assertion_linter consecutive_mutate_linter function_argument_linter if_not_else_linter if_switch_linter implicit_integer_linter inner_combine_linter is_numeric_linter keyword_quote_linter length_levels_linter literal_coercion_linter nested_pipe_linter nrow_subset_linter numeric_leading_zero_linter nzchar_linter object_name_linter paste_linter print_linter quotes_linter redundant_ifelse_linter rep_len_linter scalar_in_linter seq_linter system_file_linter T_and_F_symbol_linter unnecessary_nesting_linter which_grepl_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() function {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.","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, 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) ) #> :1:1: style: [cyclocomp_linter] Reduce the cyclomatic complexity of this function from 2 to at most 1. #> if (TRUE) 1 else 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 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 return_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 exclusions, see exclude() complete description valid values. cache_directory: location cache directory comment_token: GitHub token character error_on_lint: decides error produced lints found settings without defaults, .e., list describes every valid setting.","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_next\" \"exclude_start\" \"exclude_end\" #> [7] \"exclude_linter\" \"exclude_linter_sep\" \"exclusions\" #> [10] \"cache_directory\" \"comment_token\" \"error_on_lint\" # linters included by default names(default_settings$linters) #> [1] \"assignment_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"equals_na_linter\" \"function_left_parentheses_linter\" #> [7] \"indentation_linter\" \"infix_spaces_linter\" #> [9] \"line_length_linter\" \"object_length_linter\" #> [11] \"object_name_linter\" \"object_usage_linter\" #> [13] \"paren_body_linter\" \"pipe_continuation_linter\" #> [15] \"quotes_linter\" \"return_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: .libPaths() alternative, use withr::with_libpaths() temporary change instead permanently modifying library location. attach() alternative, use roxygen2's @importFrom statement packages, :: scripts. attach() modifies global search path. browser() alternative, remove likely leftover debugging. pauses execution run. debug() alternative, remove likely leftover debugging. traps function causes execution pause function run. debugcall() alternative, remove likely leftover debugging. traps function causes execution pause function run. debugonce() alternative, remove likely leftover debugging. traps function causes execution pause function run. detach() alternative, avoid modifying global search path. Detaching environments search path rarely necessary production code. library() alternative, use roxygen2's @importFrom statement packages :: scripts, instead modifying global search path. mapply() alternative, use Map() guarantee list returned simplify accordingly. options() alternative, use withr::with_options() temporary change instead permanently modifying session options. par() alternative, use withr::with_par() temporary change instead permanently modifying graphics device parameters. require() alternative, use roxygen2's @importFrom statement packages library() :: scripts, instead modifying global search path. sapply() alternative, use vapply() appropriate FUN.VALUE= argument obtain type-stable simplification. setwd() alternative, use withr::with_dir() temporary change instead modifying global working directory. sink() alternative, use withr::with_sink() temporary redirection instead permanently redirecting output. source() alternative, manage dependencies packages. source() loads code global environment unless local = TRUE used, can cause hard--predict behavior. structure() alternative, Use class<-, names<-, attr<- set attributes. Sys.setenv() alternative, use withr::with_envvar() temporary change instead permanently modifying global environment variables. Sys.setlocale() alternative, use withr::with_locale() temporary change instead permanently modifying session locale. trace() alternative, remove likely leftover debugging. traps function causes execution arbitrary code function run. undebug() alternative, remove likely leftover debugging. useful interactive debugging debug(). untrace() alternative, remove likely leftover debugging. useful interactive debugging trace(). following operators sometimes regarded undesirable: <<-. assigns 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(). :::. 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. <<-. assigns 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': consecutive_stopifnot_linter extraction_operator_linter no_tab_linter single_quotes_linter unnecessary_nested_if_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() ) #> :1:13: warning: [duplicate_argument_linter] Avoid duplicate arguments in function calls. #> list(x = 1, x = 2) #> ^ lint( text = \"fun(arg = 1, arg = 2)\", linters = duplicate_argument_linter() ) #> :1:14: warning: [duplicate_argument_linter] Avoid duplicate arguments in function calls. #> fun(arg = 1, arg = 2) #> ^~~ # 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 consecutive_mutate_linter fixed_regex_linter if_switch_linter ifelse_censor_linter inner_combine_linter length_test_linter lengths_linter list_comparison_linter literal_coercion_linter matrix_apply_linter nested_ifelse_linter nrow_subset_linter nzchar_linter outer_negation_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter sample_int_linter scalar_in_linter seq_linter sort_linter string_boundary_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unnecessary_lambda_linter vector_logic_linter which_grepl_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() ) #> :1:1: warning: [empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. #> x <- {} #> ^~~~~~~ writeLines(\"x = {\\n}\") #> x = { #> } lint( text = \"x = {\\n}\", linters = empty_assignment_linter() ) #> :1:1: warning: [empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. #> x = { #> ^~~~~ # 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 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() ) #> :1:1: warning: [equals_na_linter] Use is.na() instead of x == NA #> x == NA #> ^~~~~~~ lint( text = \"x != NA\", linters = equals_na_linter() ) #> :1:1: warning: [equals_na_linter] Use is.na() instead of x != NA #> x != NA #> ^~~~~~~ lint( text = \"x %in% NA\", linters = equals_na_linter() ) #> :1:1: warning: [equals_na_linter] Use is.na() instead of x %in% NA #> x %in% NA #> ^~~~~~~~~ # 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, list named /unnamed entries. Outer elements following characteristics: Unnamed elements specify filenames directories. Named elements vector list line numbers, Inf indicating 'lines'. name gives path relative config. Unnamed elements denote exclusion linters given path directory. Named elements, name specifies linter, denote exclusion linter. convenience, vector can used place list whenever introduce ambiguity, e.g. character vector files exclude vector lines exclude.","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. package authors, note includes loading package , e.g. pkgload::load_all() installing attaching package.","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_overwrite_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, pkg_testthat","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() ) #> :1:1: warning: [expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y). #> expect_true(x > y) #> ^~~~~~~~~~~~~~~~~~ lint( text = \"expect_true(x <= y)\", linters = expect_comparison_linter() ) #> :1:1: warning: [expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y). #> expect_true(x <= y) #> ^~~~~~~~~~~~~~~~~~~ lint( text = \"expect_true(x == (y == 2))\", linters = expect_comparison_linter() ) #> :1:1: warning: [expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y). #> expect_true(x == (y == 2)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~ # 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, pkg_testthat","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() ) #> :1:1: warning: [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=. #> expect_equal(x, y) #> ^~~~~~~~~~~~~~~~~~ lint( text = \"expect_true(identical(x, y))\", linters = expect_identical_linter() ) #> :1:1: warning: [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=. #> expect_true(identical(x, y)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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, pkg_testthat, 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() ) #> :1:1: warning: [expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n) #> expect_equal(length(x), 2L) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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 functions test specified linters sample code testthat testing framework. expect_lint asserts specified lints generated. expect_no_lint asserts lints generated.","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\") expect_no_lint(content, ..., 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_no_lint(\"a\", trailing_blank_lines_linter()) # one expected lint expect_lint(\"a\\n\", \"trailing blank\", trailing_blank_lines_linter()) expect_lint(\"a\\n\", list(message = \"trailing blank\", line_number = 2), trailing_blank_lines_linter()) # several expected lints expect_lint(\"a\\n\\n\", list(\"trailing blank\", \"trailing blank\"), trailing_blank_lines_linter()) expect_lint( \"a\\n\\n\", list( list(message = \"trailing blank\", line_number = 2), list(message = \"trailing blank\", 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, pkg_testthat, 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() ) #> :1:1: warning: [expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n) #> expect_equal(names(x), \"a\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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, pkg_testthat, 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() ) #> :1:1: warning: [expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa. #> expect_true(!x) #> ^~~~~~~~~~~~~~~ # 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, pkg_testthat","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() ) #> :1:1: warning: [expect_null_linter] expect_null(x) is better than expect_equal(x, NULL) #> expect_equal(x, NULL) #> ^~~~~~~~~~~~~~~~~~~~~ lint( text = \"expect_identical(x, NULL)\", linters = expect_null_linter() ) #> :1:1: warning: [expect_null_linter] expect_null(x) is better than expect_identical(x, NULL) #> expect_identical(x, NULL) #> ^~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"expect_true(is.null(x))\", linters = expect_null_linter() ) #> :1:1: warning: [expect_null_linter] expect_null(x) is better than expect_true(is.null(x)) #> 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, pkg_testthat","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() ) #> :1:1: warning: [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. #> expect_equal(class(x), \"data.frame\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'expect_equal(class(x), \"numeric\")', linters = expect_s3_class_linter() ) #> :1:1: warning: [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. #> expect_equal(class(x), \"numeric\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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, pkg_testthat","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() ) #> :1:1: warning: [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. #> expect_true(is(x, \"Matrix\")) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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, pkg_testthat, 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() ) #> :1:1: warning: [expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE) #> expect_equal(x, TRUE) #> ^~~~~~~~~~~~~~~~~~~~~ lint( text = \"expect_equal(x, FALSE)\", linters = expect_true_false_linter() ) #> :1:1: warning: [expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE) #> 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, pkg_testthat","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() ) #> :1:1: warning: [expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t) #> expect_equal(typeof(x), \"double\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'expect_identical(typeof(x), \"double\")', linters = expect_type_linter() ) #> :1:1: warning: [expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t) #> expect_identical(typeof(x), \"double\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = 'expect_type(x, \"double\")', linters = expect_type_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(allow_unescaped = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"allow_unescaped Logical, default FALSE. TRUE, patterns require regex escapes (e.g. \"\\\\$\" \"[$]\") linted. See examples.","code":""},{"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, configurable, efficiency, readability, regex","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() ) #> :1:6: warning: [fixed_regex_linter] Use \".\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. #> gsub(\"\\\\.\", \"\", x) #> ^~~~~ lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter() ) #> :1:7: warning: [fixed_regex_linter] Use \"a*b\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. #> grepl(\"a[*]b\", x) #> ^~~~~~~ lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter(allow_unescaped = TRUE) ) #> :1:7: warning: [fixed_regex_linter] Use \"a*b\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. #> grepl(\"a[*]b\", x) #> ^~~~~~~ code_lines <- 'stringr::str_subset(x, \"\\\\\\\\$\")' writeLines(code_lines) #> stringr::str_subset(x, \"\\\\$\") lint( text = code_lines, linters = fixed_regex_linter() ) #> :1:24: warning: [fixed_regex_linter] Use stringr::fixed(\"$\") as the pattern here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. #> stringr::str_subset(x, \"\\\\$\") #> ^~~~~ lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter() ) #> :1:7: warning: [fixed_regex_linter] Use \"Munich\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. #> grepl(\"Munich\", address) #> ^~~~~~~~ # 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() ) lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter(allow_unescaped = TRUE) )"},{"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() ) #> :1:6: warning: [for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. #> for (x in x) { TRUE } #> ^ lint( text = \"for (x in foo(x, y)) { TRUE }\", linters = for_loop_index_linter() ) #> :1:6: warning: [for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. #> for (x in foo(x, y)) { TRUE } #> ^ # 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() ) #> :1:24: style: [function_argument_linter] Arguments without defaults should come before arguments with defaults. #> function(y = 1, z = 2, x) {} #> ^ lint( text = \"function(x, y, z = 1, ..., w) {}\", linters = function_argument_linter() ) #> :1:28: style: [function_argument_linter] Arguments without defaults should come before arguments with defaults. #> function(x, y, z = 1, ..., w) {} #> ^ # 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() ) #> :1:5: style: [function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. #> mean (x) #> ^ lint( text = \"stats::sd(c (x, y, z))\", linters = function_left_parentheses_linter() ) #> :1:12: style: [function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. #> stats::sd(c (x, y, z)) #> ^ # 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() ) #> :1:27: warning: [function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. #> foo <- function(x) return(y <- x + 1) #> ^~~~~~~~~~ lint( text = \"foo <- function(x) return(x <<- x + 1)\", linters = function_return_linter() ) #> :1:27: warning: [function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. #> foo <- function(x) return(x <<- x + 1) #> ^~~~~~~~~~~ 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() ) #> :2:27: warning: [function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. #> foo <- function(x) return(e$val <- x + 1) #> ^~~~~~~~~~~~~~ # 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, 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 <- tempfile() writeLines(\"c('a', 'b')\", tmp) expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content writeLines(as.character(expr_as_xml)) #> #> #> #> #> c<\/SYMBOL_FUNCTION_CALL> #> <\/expr> #> (<\/OP-LEFT-PAREN> #> #> 'a'<\/STR_CONST> #> <\/expr> #> ,<\/OP-COMMA> #> #> 'b'<\/STR_CONST> #> <\/expr> #> )<\/OP-RIGHT-PAREN> #> <\/expr> #> <\/exprlist> #> get_r_string(expr_as_xml, \"expr[2]\") #> [1] \"a\" get_r_string(expr_as_xml, \"expr[3]\") #> [1] \"b\" unlink(tmp) # more importantly, extract raw strings correctly tmp_raw <- tempfile() writeLines(\"c(R'(a\\\\b)', R'--[a\\\\\\\"\\'\\\"\\\\b]--')\", tmp_raw) expr_as_xml_raw <- get_source_expressions(tmp_raw)$expressions[[1L]]$xml_parsed_content writeLines(as.character(expr_as_xml_raw)) #> #> #> #> #> c<\/SYMBOL_FUNCTION_CALL> #> <\/expr> #> (<\/OP-LEFT-PAREN> #> #> R'(a\\b)'<\/STR_CONST> #> <\/expr> #> ,<\/OP-COMMA> #> #> R'--[a\\\"'\"\\b]--'<\/STR_CONST> #> <\/expr> #> )<\/OP-RIGHT-PAREN> #> <\/expr> #> <\/exprlist> #> get_r_string(expr_as_xml_raw, \"expr[2]\") #> [1] \"a\\\\b\" get_r_string(expr_as_xml_raw, \"expr[3]\") #> [1] \"a\\\\\\\"'\\\"\\\\b\" unlink(tmp_raw)"},{"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 8 elements: filename (character) name file. line (integer) line file expression begins. column (integer) column file expression begins. lines (named character) vector lines spanned expression, named corresponding line numbers. 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). xml_find_function_calls(function_names) (function) function returns SYMBOL_FUNCTION_CALL XML nodes xml_parsed_content specified function names. final element expressions list corresponding full file consisting 7 elements: filename (character) name file. 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). xml_find_function_calls(function_names) (function) function returns SYMBOL_FUNCTION_CALL XML nodes full_xml_parsed_content specified function names. 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 <- tempfile() writeLines(c(\"x <- 1\", \"y <- x + 1\"), tmp) get_source_expressions(tmp) #> $expressions #> $expressions[[1]] #> $expressions[[1]]$filename #> [1] \"/tmp/RtmpVnxWsC/file173b52be4ff0\" #> #> $expressions[[1]]$line #> [1] 1 #> #> $expressions[[1]]$column #> [1] 1 #> #> $expressions[[1]]$lines #> 1 #> \"x <- 1\" #> #> $expressions[[1]]$parsed_content #> line1 col1 line2 col2 id parent token terminal text #> 7 1 1 1 6 7 0 expr FALSE #> 1 1 1 1 1 1 3 SYMBOL TRUE x #> 3 1 1 1 1 3 7 expr FALSE #> 2 1 3 1 4 2 7 LEFT_ASSIGN TRUE <- #> 4 1 6 1 6 4 5 NUM_CONST TRUE 1 #> 5 1 6 1 6 5 7 expr FALSE #> #> $expressions[[1]]$xml_parsed_content #> {xml_document} #> #> [1] \\n #> $expressions[[1]]$xml_find_function_calls #> function (function_names, keep_names = FALSE) #> { #> if (is.null(function_names)) { #> res <- function_call_cache #> } #> else { #> res <- function_call_cache[names(function_call_cache) %in% #> function_names] #> } #> if (keep_names) #> res #> else unname(res) #> } #> #> #> #> $expressions[[1]]$content #> [1] \"x <- 1\" #> #> #> $expressions[[2]] #> $expressions[[2]]$filename #> [1] \"/tmp/RtmpVnxWsC/file173b52be4ff0\" #> #> $expressions[[2]]$line #> [1] 2 #> #> $expressions[[2]]$column #> [1] 1 #> #> $expressions[[2]]$lines #> 2 #> \"y <- x + 1\" #> #> $expressions[[2]]$parsed_content #> line1 col1 line2 col2 id parent token terminal text #> 20 2 1 2 10 20 0 expr FALSE #> 10 2 1 2 1 10 12 SYMBOL TRUE y #> 12 2 1 2 1 12 20 expr FALSE #> 11 2 3 2 4 11 20 LEFT_ASSIGN TRUE <- #> 19 2 6 2 10 19 20 expr FALSE #> 13 2 6 2 6 13 15 SYMBOL TRUE x #> 15 2 6 2 6 15 19 expr FALSE #> 14 2 8 2 8 14 19 '+' TRUE + #> 16 2 10 2 10 16 17 NUM_CONST TRUE 1 #> 17 2 10 2 10 17 19 expr FALSE #> #> $expressions[[2]]$xml_parsed_content #> {xml_document} #> #> [1] \\n #> $expressions[[2]]$xml_find_function_calls #> function (function_names, keep_names = FALSE) #> { #> if (is.null(function_names)) { #> res <- function_call_cache #> } #> else { #> res <- function_call_cache[names(function_call_cache) %in% #> function_names] #> } #> if (keep_names) #> res #> else unname(res) #> } #> #> #> #> $expressions[[2]]$content #> [1] \"y <- x + 1\" #> #> #> $expressions[[3]] #> $expressions[[3]]$filename #> [1] \"/tmp/RtmpVnxWsC/file173b52be4ff0\" #> #> $expressions[[3]]$file_lines #> 1 2 #> \"x <- 1\" \"y <- x + 1\" #> attr(,\"terminal_newline\") #> [1] TRUE #> #> $expressions[[3]]$content #> 1 2 #> \"x <- 1\" \"y <- x + 1\" #> attr(,\"terminal_newline\") #> [1] TRUE #> #> $expressions[[3]]$full_parsed_content #> line1 col1 line2 col2 id parent token terminal text #> 7 1 1 1 6 7 0 expr FALSE #> 1 1 1 1 1 1 3 SYMBOL TRUE x #> 3 1 1 1 1 3 7 expr FALSE #> 2 1 3 1 4 2 7 LEFT_ASSIGN TRUE <- #> 4 1 6 1 6 4 5 NUM_CONST TRUE 1 #> 5 1 6 1 6 5 7 expr FALSE #> 20 2 1 2 10 20 0 expr FALSE #> 10 2 1 2 1 10 12 SYMBOL TRUE y #> 12 2 1 2 1 12 20 expr FALSE #> 11 2 3 2 4 11 20 LEFT_ASSIGN TRUE <- #> 19 2 6 2 10 19 20 expr FALSE #> 13 2 6 2 6 13 15 SYMBOL TRUE x #> 15 2 6 2 6 15 19 expr FALSE #> 14 2 8 2 8 14 19 '+' TRUE + #> 16 2 10 2 10 16 17 NUM_CONST TRUE 1 #> 17 2 10 2 10 17 19 expr FALSE #> #> $expressions[[3]]$full_xml_parsed_content #> {xml_document} #> #> [1] \\n [2] \\n #> $expressions[[3]]$xml_find_function_calls #> function (function_names, keep_names = FALSE) #> { #> if (is.null(function_names)) { #> res <- function_call_cache #> } #> else { #> res <- function_call_cache[names(function_call_cache) %in% #> function_names] #> } #> if (keep_names) #> res #> else unname(res) #> } #> #> #> #> $expressions[[3]]$terminal_newline #> [1] TRUE #> #> #> #> $error #> NULL #> #> $lines #> 1 2 #> \"x <- 1\" \"y <- x + 1\" #> attr(,\"terminal_newline\") #> [1] TRUE #> unlink(tmp)"},{"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 <- tempfile() writeLines(c(\"x <- 1\", \"y <- x + 1\"), tmp) source_exprs <- get_source_expressions(tmp) ids_with_token(source_exprs$expressions[[1L]], value = \"SYMBOL\") #> [1] 2 with_id(source_exprs$expressions[[1L]], 2L) #> line1 col1 line2 col2 id parent token terminal text #> 1 1 1 1 1 1 3 SYMBOL TRUE x unlink(tmp)"},{"path":"https://lintr.r-lib.org/dev/reference/if_not_else_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block statements like if (!A) x else y — if_not_else_linter","title":"Block statements like if (!A) x else y — if_not_else_linter","text":"(!) x else y () y else x, latter easier reason else case. former requires double negation can avoided switching statement order.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/if_not_else_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block statements like if (!A) x else y — if_not_else_linter","text":"","code":"if_not_else_linter(exceptions = c(\"is.null\", \"is.na\", \"missing\"))"},{"path":"https://lintr.r-lib.org/dev/reference/if_not_else_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block statements like if (!A) x else y — if_not_else_linter","text":"exceptions Character vector calls exclude linting. default, .null(), .na(), missing() excluded given common idiom !.na(x) \"x present\".","code":""},{"path":"https://lintr.r-lib.org/dev/reference/if_not_else_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block statements like if (!A) x else y — if_not_else_linter","text":"applies simple /else case. Statements like (!) x else (B) y else z always simpler readable form. also applies ifelse() package equivalents dplyr::if_else() data.table::fifelse().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/if_not_else_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block statements like if (!A) x else y — if_not_else_linter","text":"configurable, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/if_not_else_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block statements like if (!A) x else y — if_not_else_linter","text":"","code":"# will produce lints lint( text = \"if (!A) x else y\", linters = if_not_else_linter() ) #> :1:5: warning: [if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement. #> if (!A) x else y #> ^~ lint( text = \"if (!A) x else if (!B) y else z\", linters = if_not_else_linter() ) #> :1:20: warning: [if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement. #> if (!A) x else if (!B) y else z #> ^~ lint( text = \"ifelse(!is_treatment, x, y)\", linters = if_not_else_linter() ) #> :1:1: warning: [if_not_else_linter] Prefer `ifelse(A, x, y)` to the less-readable `ifelse(!A, y, x)`. #> ifelse(!is_treatment, x, y) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"if (!is.null(x)) x else 2\", linters = if_not_else_linter(exceptions = character()) ) #> :1:5: warning: [if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement. #> if (!is.null(x)) x else 2 #> ^~~~~~~~~~~ # okay lint( text = \"if (A) x else y\", linters = if_not_else_linter() ) lint( text = \"if (!A) x else if (B) z else y\", linters = if_not_else_linter() ) lint( text = \"ifelse(is_treatment, y, x)\", linters = if_not_else_linter() ) lint( text = \"if (!is.null(x)) x else 2\", linters = if_not_else_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/if_switch_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of switch() over repeated if/else blocks — if_switch_linter","title":"Require usage of switch() over repeated if/else blocks — if_switch_linter","text":"switch() statements R used delegate behavior based value input scalar string, e.g. switch(x, = 1, b = 3, c = 7, d = 8) one 1, 3, 7, 8, depending value x.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/if_switch_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of switch() over repeated if/else blocks — if_switch_linter","text":"","code":"if_switch_linter(max_branch_lines = 0L, max_branch_expressions = 0L)"},{"path":"https://lintr.r-lib.org/dev/reference/if_switch_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Require usage of switch() over repeated if/else blocks — if_switch_linter","text":"max_branch_lines, max_branch_expressions Integer, default 0 indicates \"maximum\". set /else /.../else chain branch occupies number lines (resp. expressions) linted. conjugate applies switch() statements – parameters set, switch() statement overly-complicated branches linted. See examples.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/if_switch_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of switch() over repeated if/else blocks — if_switch_linter","text":"can also accomplished repeated /else statements like : (x == \"\") 1 else (x == \"b\") 2 else (x == \"c\") 7 else 8 (implicitly, last else assumes x takes 4 possible values), cluttered slower (note switch() takes time evaluate regardless value x, faster even x takes first value (), /else approach roughly linear number conditions need evaluated, 3 times).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/if_switch_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of switch() over repeated if/else blocks — if_switch_linter","text":"best_practices, configurable, consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/if_switch_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of switch() over repeated if/else blocks — if_switch_linter","text":"","code":"# will produce lints lint( text = \"if (x == 'a') 1 else if (x == 'b') 2 else 3\", linters = if_switch_linter() ) code <- paste( \"if (x == 'a') {\", \" 1\", \"} else if (x == 'b') {\", \" 2\", \"} else if (x == 'c') {\", \" y <- x\", \" z <- sqrt(match(y, letters))\", \" z\", \"}\", sep = \"\\n\" ) writeLines(code) #> if (x == 'a') { #> 1 #> } else if (x == 'b') { #> 2 #> } else if (x == 'c') { #> y <- x #> z <- sqrt(match(y, letters)) #> z #> } lint( text = code, linters = if_switch_linter() ) #> :1:1: warning: [if_switch_linter] Prefer switch() statements over repeated if/else equality tests, e.g., switch(x, a = 1, b = 2) over if (x == \"a\") 1 else if (x == \"b\") 2. #> if (x == 'a') { #> ^~~~~~~~~~~~~~~ code <- paste( \"if (x == 'a') {\", \" 1\", \"} else if (x == 'b') {\", \" 2\", \"} else if (x == 'c') {\", \" y <- x\", \" z <- sqrt(\", \" match(y, letters)\", \" )\", \" z\", \"}\", sep = \"\\n\" ) writeLines(code) #> if (x == 'a') { #> 1 #> } else if (x == 'b') { #> 2 #> } else if (x == 'c') { #> y <- x #> z <- sqrt( #> match(y, letters) #> ) #> z #> } lint( text = code, linters = if_switch_linter() ) #> :1:1: warning: [if_switch_linter] Prefer switch() statements over repeated if/else equality tests, e.g., switch(x, a = 1, b = 2) over if (x == \"a\") 1 else if (x == \"b\") 2. #> if (x == 'a') { #> ^~~~~~~~~~~~~~~ code <- paste( \"switch(x,\", \" a = {\", \" 1\", \" 2\", \" 3\", \" },\", \" b = {\", \" 1\", \" 2\", \" }\", \")\", sep = \"\\n\" ) writeLines(code) #> switch(x, #> a = { #> 1 #> 2 #> 3 #> }, #> b = { #> 1 #> 2 #> } #> ) lint( text = code, linters = if_switch_linter(max_branch_lines = 2L) ) #> :1:1: warning: [if_switch_linter] Prefer repeated if/else statements over overly-complicated switch() statements. #> switch(x, #> ^~~~~~~~~ # okay lint( text = \"switch(x, a = 1, b = 2, 3)\", linters = if_switch_linter() ) # switch() version not as clear lint( text = \"if (x == 'a') 1 else if (x == 'b' & y == 2) 2 else 3\", linters = if_switch_linter() ) code <- paste( \"if (x == 'a') {\", \" 1\", \"} else if (x == 'b') {\", \" 2\", \"} else if (x == 'c') {\", \" y <- x\", \" z <- sqrt(match(y, letters))\", \" z\", \"}\", sep = \"\\n\" ) writeLines(code) #> if (x == 'a') { #> 1 #> } else if (x == 'b') { #> 2 #> } else if (x == 'c') { #> y <- x #> z <- sqrt(match(y, letters)) #> z #> } lint( text = code, linters = if_switch_linter(max_branch_lines = 2L) ) code <- paste( \"if (x == 'a') {\", \" 1\", \"} else if (x == 'b') {\", \" 2\", \"} else if (x == 'c') {\", \" y <- x\", \" z <- sqrt(\", \" match(y, letters)\", \" )\", \" z\", \"}\", sep = \"\\n\" ) writeLines(code) #> if (x == 'a') { #> 1 #> } else if (x == 'b') { #> 2 #> } else if (x == 'c') { #> y <- x #> z <- sqrt( #> match(y, letters) #> ) #> z #> } lint( text = code, linters = if_switch_linter(max_branch_expressions = 2L) ) code <- paste( \"switch(x,\", \" a = {\", \" 1\", \" 2\", \" 3\", \" },\", \" b = {\", \" 1\", \" 2\", \" }\", \")\", sep = \"\\n\" ) writeLines(code) #> switch(x, #> a = { #> 1 #> 2 #> 3 #> }, #> b = { #> 1 #> 2 #> } #> ) lint( text = code, linters = if_switch_linter(max_branch_lines = 3L) )"},{"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() ) #> :1:1: warning: [ifelse_censor_linter] pmin(x, y) is preferable to ifelse(x < y, x, y). #> ifelse(5:1 < pi, 5:1, pi) #> ^~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"ifelse(x > 0, x, 0)\", linters = ifelse_censor_linter() ) #> :1:1: warning: [ifelse_censor_linter] pmax(x, y) is preferable to ifelse(x > y, x, y). #> ifelse(x > 0, x, 0) #> ^~~~~~~~~~~~~~~~~~~ # 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\"), allow_lazy = FALSE, allow_scoped = FALSE )"},{"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. allow_lazy logical, default FALSE. TRUE, assignments trigger conditionally (e.g. RHS && || expressions) skipped. allow_scoped Logical, default FALSE. TRUE, \"scoped assignments\", object assigned statement beginning branch used within branch, skipped.","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() ) #> :1:5: warning: [implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. #> if (x <- 1L) TRUE #> ^~~~~~~ lint( text = \"mean(x <- 1:4)\", linters = implicit_assignment_linter() ) #> :1:6: warning: [implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. #> mean(x <- 1:4) #> ^~~~~~~~ # okay lines <- \"x <- 1L\\nif (x) TRUE\" writeLines(lines) #> x <- 1L #> if (x) TRUE lint( text = lines, linters = implicit_assignment_linter() ) lines <- \"x <- 1:4\\nmean(x)\" writeLines(lines) #> x <- 1:4 #> mean(x) lint( text = lines, linters = implicit_assignment_linter() ) lint( text = \"A && (B <- foo(A))\", linters = implicit_assignment_linter(allow_lazy = TRUE) ) lines <- c( \"if (any(idx <- x < 0)) {\", \" stop('negative elements: ', toString(which(idx)))\", \"}\" ) writeLines(lines) #> if (any(idx <- x < 0)) { #> stop('negative elements: ', toString(which(idx))) #> } lint( text = lines, linters = implicit_assignment_linter(allow_scoped = TRUE) )"},{"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() ) #> :1:7: style: [implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers. #> x <- 1 #> ~^ lint( text = \"x[2]\", linters = implicit_integer_linter() ) #> :1:4: style: [implicit_integer_linter] Use 2L or 2.0 to avoid implicit integers. #> x[2] #> ~^ lint( text = \"1:10\", linters = implicit_integer_linter() ) #> :1:2: style: [implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers. #> 1:10 #> ~^ #> :1:5: style: [implicit_integer_linter] Use 10L or 10.0 to avoid implicit integers. #> 1:10 #> ~~^ # 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() ) #> :2:0: style: [indentation_linter] Indentation should be 2 spaces but is 0 spaces. #> 1 + 1 #> ^~ code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> :2:4: style: [indentation_linter] Indentation should be 2 spaces but is 4 spaces. #> 1 + 1 #> ~^ 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\") ) #> :2:2: style: [indentation_linter] Hanging indent should be 4 spaces but is 2 spaces. #> additional_arg = 42 #> ^~~ 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\") ) #> :2:4: style: [indentation_linter] Indentation should be 2 spaces but is 4 spaces. #> additional_arg = 42) #> ~^ # 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 \"=\" includes three different operators, parser's point view. lint , pass corresponding parse tags (.e., \"EQ_ASSIGN\", \"EQ_SUB\", \"EQ_FORMALS\"; see utils::getParseData()). 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() ) #> :1:2: style: [infix_spaces_linter] Put spaces around all infix operators. #> x<-1L #> ^~ lint( text = \"1:4 %>%sum()\", linters = infix_spaces_linter() ) #> :1:5: style: [infix_spaces_linter] Put spaces around all infix operators. #> 1:4 %>%sum() #> ^~~ # 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 = \"||\") ) lint( text = \"sum(1:10, na.rm=TRUE)\", linters = infix_spaces_linter(exclude_operators = \"EQ_SUB\") )"},{"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":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"Note strptime() one idiosyncrasy aware , namely auto-detected format= set first matching input, means case like c(.POSIXct(\"2024-01-01\"), .POSIXct(\"2024-01-01 01:02:03\")) gives different results .POSIXct(c(\"2024-01-01\", \"2024-01-01 01:02:03\")). false positive rare; workaround possible use consistent formatting, .e., \"2024-01-01 00:00:00\" example.","code":""},{"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() ) #> :1:1: warning: [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)). #> c(log10(x), log10(y), log10(z)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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 <- tempfile() writeLines(c(\"x <- 1\", \"y <- x + 1\"), tmp) source_exprs <- get_source_expressions(tmp) is_lint_level(source_exprs$expressions[[1L]], level = \"expression\") #> [1] TRUE is_lint_level(source_exprs$expressions[[1L]], level = \"file\") #> [1] FALSE is_lint_level(source_exprs$expressions[[3L]], level = \"expression\") #> [1] FALSE is_lint_level(source_exprs$expressions[[3L]], level = \"file\") #> [1] TRUE unlink(tmp)"},{"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() ) #> :1:1: warning: [is_numeric_linter] Use `is.numeric(x)` instead of the equivalent `is.numeric(x) || is.integer(x)`. Use is.double(x) to test for objects stored as 64-bit floating point. #> is.numeric(y) || is.integer(y) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'class(z) %in% c(\"numeric\", \"integer\")', linters = is_numeric_linter() ) #> :1:1: warning: [is_numeric_linter] Use is.numeric(x) instead of class(x) %in% c(\"integer\", \"numeric\"). Use is.double(x) to test for objects stored as 64-bit floating point. #> class(z) %in% c(\"numeric\", \"integer\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 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/keyword_quote_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block unnecessary quoting in calls — keyword_quote_linter","title":"Block unnecessary quoting in calls — keyword_quote_linter","text":"valid symbol can used keyword argument R function call. Sometimes, necessary quote (backtick) argument otherwise valid symbol (e.g. creating vector whose names spaces); besides edge case, quoting done.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/keyword_quote_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block unnecessary quoting in calls — keyword_quote_linter","text":"","code":"keyword_quote_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/keyword_quote_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block unnecessary quoting in calls — keyword_quote_linter","text":"common source violation creating named vectors, lists, data.frame-alikes, can observed calls well. Similar reasoning applies extractions $ @.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/keyword_quote_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block unnecessary quoting in calls — keyword_quote_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/keyword_quote_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block unnecessary quoting in calls — keyword_quote_linter","text":"","code":"# will produce lints lint( text = 'data.frame(\"a\" = 1)', linters = keyword_quote_linter() ) #> :1:12: warning: [keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names). #> data.frame(\"a\" = 1) #> ^~~ lint( text = \"data.frame(`a` = 1)\", linters = keyword_quote_linter() ) #> :1:12: warning: [keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names). #> data.frame(`a` = 1) #> ^~~ lint( text = 'my_list$\"key\"', linters = keyword_quote_linter() ) #> :1:9: warning: [keyword_quote_linter] Only quote targets of extraction with $ if necessary, i.e., if the name is not a valid R symbol (see ?make.names). Use backticks to create non-syntactic names, or use [[ to extract by string. #> my_list$\"key\" #> ^~~~~ lint( text = 's4obj@\"key\"', linters = keyword_quote_linter() ) #> :1:7: warning: [keyword_quote_linter] Only quote targets of extraction with @ if necessary, i.e., if the name is not a valid R symbol (see ?make.names). Use backticks to create non-syntactic names, or use slot() to extract by string. #> s4obj@\"key\" #> ^~~~~ # okay lint( text = \"data.frame(`a b` = 1)\", linters = keyword_quote_linter() ) lint( text = \"my_list$`a b`\", linters = keyword_quote_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/length_levels_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of nlevels over length(levels(.)) — length_levels_linter","title":"Require usage of nlevels over length(levels(.)) — length_levels_linter","text":"length(levels(x)) nlevels(x), harder read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/length_levels_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of nlevels over length(levels(.)) — length_levels_linter","text":"","code":"length_levels_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/length_levels_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of nlevels over length(levels(.)) — length_levels_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/length_levels_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of nlevels over length(levels(.)) — length_levels_linter","text":"","code":"# will produce lints lint( text = \"length(levels(x))\", linters = length_levels_linter() ) #> :1:1: warning: [length_levels_linter] nlevels(x) is better than length(levels(x)). #> length(levels(x)) #> ^~~~~~~~~~~~~~~~~ # okay lint( text = \"length(c(levels(x), levels(y)))\", linters = length_levels_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/length_test_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check for a common mistake where length is applied in the wrong place — length_test_linter","title":"Check for a common mistake where length is applied in the wrong place — length_test_linter","text":"Usage like length(x == 0) mistake. intended check x empty, use length(x) == 0. mistakes possible, running length() outcome logical comparison never best choice.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/length_test_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check for a common mistake where length is applied in the wrong place — length_test_linter","text":"","code":"length_test_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/length_test_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check for a common mistake where length is applied in the wrong place — length_test_linter","text":"best_practices, consistency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/length_test_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check for a common mistake where length is applied in the wrong place — length_test_linter","text":"","code":"# will produce lints lint( text = \"length(x == 0)\", linters = length_test_linter() ) #> :1:1: warning: [length_test_linter] Checking the length of a logical vector is likely a mistake. Did you mean `length(x) == 0`? #> length(x == 0) #> ^~~~~~~~~~~~~~ # okay lint( text = \"length(x) > 0\", linters = length_test_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() ) #> :1:1: warning: [lengths_linter] Use lengths() to find the length of each element in a list. #> sapply(x, length) #> ^~~~~~~~~~~~~~~~~ lint( text = \"vapply(x, length, integer(1L))\", linters = lengths_linter() ) #> :1:1: warning: [lengths_linter] Use lengths() to find the length of each element in a list. #> vapply(x, length, integer(1L)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"purrr::map_int(x, length)\", linters = lengths_linter() ) #> :1:1: warning: [lengths_linter] Use lengths() to find the length of each element in a list. #> purrr::map_int(x, length) #> ^~~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = \"lengths(x)\", linters = lengths_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/library_call_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Library call linter — library_call_linter","title":"Library call linter — library_call_linter","text":"linter covers several rules related library() calls:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/library_call_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Library call linter — library_call_linter","text":"","code":"library_call_linter(allow_preamble = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/library_call_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Library call linter — library_call_linter","text":"allow_preamble Logical, default TRUE. FALSE, code allowed precede first library() call, otherwise setup code allowed, library() calls must follow consecutively first one.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/library_call_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Library call linter — library_call_linter","text":"Enforce calls top script. Block usage argument character., particular loading packages loop. Block consecutive calls suppressMessages(library(.)) favor using suppressMessages() suppress messages library() calls. Ditto suppressPackageStartupMessages().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/library_call_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Library call linter — library_call_linter","text":"best_practices, configurable, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/library_call_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Library call linter — library_call_linter","text":"","code":"# will produce lints code <- \"library(dplyr)\\nprint('test')\\nlibrary(tidyr)\" writeLines(code) #> library(dplyr) #> print('test') #> library(tidyr) lint( text = code, linters = library_call_linter() ) #> :3:1: warning: [library_call_linter] Move all library calls to the top of the script. #> library(tidyr) #> ^~~~~~~~~~~~~~ lint( text = \"library('dplyr', character.only = TRUE)\", linters = library_call_linter() ) #> :1:1: warning: [library_call_linter] Use symbols in library calls to avoid the need for 'character.only'. #> library('dplyr', character.only = TRUE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ code <- paste( \"pkg <- c('dplyr', 'tibble')\", \"sapply(pkg, library, character.only = TRUE)\", sep = \"\\n\" ) writeLines(code) #> pkg <- c('dplyr', 'tibble') #> sapply(pkg, library, character.only = TRUE) lint( text = code, linters = library_call_linter() ) #> :2:1: warning: [library_call_linter] Call library() directly, not vectorized with sapply(). #> sapply(pkg, library, character.only = TRUE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ code <- \"suppressMessages(library(dplyr))\\nsuppressMessages(library(tidyr))\" writeLines(code) #> suppressMessages(library(dplyr)) #> suppressMessages(library(tidyr)) lint( text = code, linters = library_call_linter() ) #> :1:1: warning: [library_call_linter] Unify consecutive calls to suppressMessages(). You can do so by writing all of the calls in one braced expression like suppressMessages({...}). #> suppressMessages(library(dplyr)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # okay code <- \"library(dplyr)\\nprint('test')\" writeLines(code) #> library(dplyr) #> print('test') lint( text = code, linters = library_call_linter() ) code <- \"# comment\\nlibrary(dplyr)\" lint( text = code, linters = library_call_linter() ) code <- paste( \"foo <- function(pkg) {\", \" sapply(pkg, library, character.only = TRUE)\", \"}\", sep = \"\\n\" ) writeLines(code) #> foo <- function(pkg) { #> sapply(pkg, library, character.only = TRUE) #> } lint( text = code, linters = library_call_linter() ) code <- \"suppressMessages({\\n library(dplyr)\\n library(tidyr)\\n})\" writeLines(code) #> suppressMessages({ #> library(dplyr) #> library(tidyr) #> }) lint( text = code, linters = library_call_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) ) #> :1:21: style: [line_length_linter] Lines should not be more than 20 characters. This line is 23 characters. #> xxxxxxxxxxxxxxxxxxxxxxx #> ~~~~~~~~~~~~~~~~~~~~^~~ # 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 = \"(?i)[.](r|rmd|qmd|rnw|rhtml|rrst|rtex|rtxt)$\", parse_settings = TRUE, show_progress = NULL ) lint_package( path = \".\", ..., relative_path = TRUE, exclusions = list(\"R/RcppExports.R\"), parse_settings = TRUE, show_progress = NULL )"},{"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 logical, toggle caching lint results. passed character string, store cache directory. parse_settings Logical, default TRUE. Whether try parse settings. Otherwise, default_settings() used. 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, ...). show_progress Logical controlling whether show linting progress simple text progress bar via utils::txtProgressBar(). default behavior show progress interactive() sessions running testthat suite.","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 <- tempfile() writeLines(\"a=1\", f) lint(f) # linting a file #> /tmp/RtmpVnxWsC/file173b1162aca6:1:2: style: [assignment_linter] Use <-, not =, for assignment. #> a=1 #> ^ #> /tmp/RtmpVnxWsC/file173b1162aca6:1:2: style: [infix_spaces_linter] Put spaces around all infix operators. #> a=1 #> ^ lint(\"a = 123\\n\") # linting inline-code #> :1:3: style: [assignment_linter] Use <-, not =, for assignment. #> a = 123 #> ^ lint(text = \"a = 123\") # linting inline-code #> :1:3: style: [assignment_linter] Use <-, not =, for assignment. #> a = 123 #> ^ unlink(f) 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 (63 linters) common_mistakes (11 linters) configurable (44 linters) consistency (32 linters) correctness (7 linters) default (25 linters) deprecated (6 linters) efficiency (32 linters) executing (6 linters) package_development (14 linters) pkg_testthat (12 linters) readability (64 linters) regex (4 linters) robustness (17 linters) style (40 linters) tidy_design (1 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: configurable, default, readability, style) commented_code_linter (tags: best_practices, default, readability, style) comparison_negation_linter (tags: consistency, readability) condition_call_linter (tags: best_practices, configurable, style, tidy_design) condition_message_linter (tags: best_practices, consistency) conjunct_test_linter (tags: best_practices, configurable, package_development, pkg_testthat, readability) consecutive_assertion_linter (tags: consistency, readability, style) consecutive_mutate_linter (tags: configurable, consistency, efficiency, readability) cyclocomp_linter (tags: best_practices, configurable, 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, pkg_testthat) expect_identical_linter (tags: package_development, pkg_testthat) expect_length_linter (tags: best_practices, package_development, pkg_testthat, readability) expect_named_linter (tags: best_practices, package_development, pkg_testthat, readability) expect_not_linter (tags: best_practices, package_development, pkg_testthat, readability) expect_null_linter (tags: best_practices, package_development, pkg_testthat) expect_s3_class_linter (tags: best_practices, package_development, pkg_testthat) expect_s4_class_linter (tags: best_practices, package_development, pkg_testthat) expect_true_false_linter (tags: best_practices, package_development, pkg_testthat, readability) expect_type_linter (tags: best_practices, package_development, pkg_testthat) fixed_regex_linter (tags: best_practices, configurable, efficiency, readability, regex) 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) if_not_else_linter (tags: configurable, consistency, readability) if_switch_linter (tags: best_practices, configurable, consistency, efficiency, 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) keyword_quote_linter (tags: consistency, readability, style) length_levels_linter (tags: best_practices, consistency, readability) length_test_linter (tags: common_mistakes, efficiency) lengths_linter (tags: best_practices, efficiency, readability) library_call_linter (tags: best_practices, configurable, readability, style) line_length_linter (tags: configurable, default, readability, style) list_comparison_linter (tags: best_practices, common_mistakes, efficiency) 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) nested_pipe_linter (tags: configurable, consistency, readability) nonportable_path_linter (tags: best_practices, configurable, robustness) nrow_subset_linter (tags: best_practices, consistency, efficiency) numeric_leading_zero_linter (tags: consistency, readability, style) nzchar_linter (tags: best_practices, consistency, efficiency) object_length_linter (tags: configurable, default, executing, readability, style) object_name_linter (tags: configurable, consistency, default, executing, style) object_overwrite_linter (tags: best_practices, configurable, executing, readability, robustness) object_usage_linter (tags: configurable, correctness, default, executing, readability, style) one_call_pipe_linter (tags: 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_consistency_linter (tags: configurable, readability, style) pipe_continuation_linter (tags: default, readability, style) pipe_return_linter (tags: best_practices, common_mistakes) print_linter (tags: best_practices, consistency) 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, regex) rep_len_linter (tags: best_practices, consistency, readability) repeat_linter (tags: readability, style) return_linter (tags: configurable, default, style) routine_registration_linter (tags: best_practices, efficiency, robustness) sample_int_linter (tags: efficiency, readability, robustness) scalar_in_linter (tags: best_practices, configurable, consistency, efficiency, readability) 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) stopifnot_all_linter (tags: best_practices, readability) string_boundary_linter (tags: configurable, efficiency, readability, regex) 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) terminal_close_linter (tags: best_practices, robustness) 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, configurable, efficiency, readability) unnecessary_nesting_linter (tags: best_practices, configurable, consistency, readability) unnecessary_placeholder_linter (tags: best_practices, readability) unreachable_code_linter (tags: best_practices, configurable, readability) unused_import_linter (tags: best_practices, common_mistakes, configurable, executing) vector_logic_linter (tags: best_practices, common_mistakes, default, efficiency) which_grepl_linter (tags: consistency, efficiency, readability, regex) whitespace_linter (tags: consistency, default, style) yoda_test_linter (tags: best_practices, package_development, pkg_testthat, 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)"},{"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 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 <- tempfile() writeLines(\"my_slightly_long_variable_name <- 2.3\", f) lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120L))) unlink(f) # the default linter list with a different line length cutoff my_linters <- linters_with_defaults(line_length_linter = line_length_linter(120L)) # 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] \"equals_na_linter\" \"function_left_parentheses_linter\" #> [7] \"indentation_linter\" \"infix_spaces_linter\" #> [9] \"line_length_linter\" \"object_length_linter\" #> [11] \"object_name_linter\" \"object_usage_linter\" #> [13] \"paren_body_linter\" \"pipe_continuation_linter\" #> [15] \"quotes_linter\" \"return_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. exclude_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded. Note linters tag \"defunct\" (work can longer run) queried directly. See lintr-deprecated instead.","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\" \"condition_call_linter\" #> [7] \"conjunct_test_linter\" \"consecutive_assertion_linter\" #> [9] \"cyclocomp_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\" \"function_argument_linter\" #> [21] \"function_left_parentheses_linter\" \"implicit_assignment_linter\" #> [23] \"implicit_integer_linter\" \"indentation_linter\" #> [25] \"infix_spaces_linter\" \"keyword_quote_linter\" #> [27] \"library_call_linter\" \"line_length_linter\" #> [29] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [31] \"object_name_linter\" \"object_usage_linter\" #> [33] \"one_call_pipe_linter\" \"package_hooks_linter\" #> [35] \"paren_body_linter\" \"pipe_call_linter\" #> [37] \"pipe_consistency_linter\" \"pipe_continuation_linter\" #> [39] \"quotes_linter\" \"repeat_linter\" #> [41] \"return_linter\" \"semicolon_linter\" #> [43] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [45] \"T_and_F_symbol_linter\" \"todo_comment_linter\" #> [47] \"trailing_blank_lines_linter\" \"trailing_whitespace_linter\" #> [49] \"undesirable_function_linter\" \"undesirable_operator_linter\" #> [51] \"unnecessary_concatenation_linter\" \"whitespace_linter\" #> [53] \"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() (use brace_linter()) closed_curly_linter() (use brace_linter()) paren_brace_linter() (use brace_linter()) semicolon_terminator_linter() (use 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() extraction_operator_linter() unnecessary_nested_if_linter() with_defaults(..., default = default_linters)"},{"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, semicolon Irrelevant parameters defunct linters.","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":"consistency, 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: Michael Chirico michaelchirico4@gmail.com Authors: Jim Hester Florent Angly (fangly) Russ Hyde Kun Ren Alexander Rosenstock (AshesITR) Indrajeet Patil patilindrajeet.science@gmail.com (ORCID) (@patilindrajeets)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/list_comparison_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of comparison operators with known-list() functions like lapply — list_comparison_linter","title":"Block usage of comparison operators with known-list() functions like lapply — list_comparison_linter","text":"Usage like lapply(x, sum) > 10 awkward list must first coerced vector comparison. function like vapply() preferred.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/list_comparison_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of comparison operators with known-list() functions like lapply — list_comparison_linter","text":"","code":"list_comparison_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/list_comparison_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of comparison operators with known-list() functions like lapply — list_comparison_linter","text":"best_practices, common_mistakes, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/list_comparison_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of comparison operators with known-list() functions like lapply — list_comparison_linter","text":"","code":"# will produce lints lint( text = \"lapply(x, sum) > 10\", linters = list_comparison_linter() ) #> :1:1: warning: [list_comparison_linter] The output of lapply(), a list(), is being coerced for comparison by `>`. Instead, use a mapper that generates a vector with the correct type directly, for example vapply(x, FUN, character(1L)) if the output is a string. #> lapply(x, sum) > 10 #> ^~~~~~~~~~~~~~~~~~~ # okay lint( text = \"unlist(lapply(x, sum)) > 10\", linters = list_comparison_linter() )"},{"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() ) #> :1:1: warning: [literal_coercion_linter] Use 1L instead of int(1), i.e., use literals directly where possible, instead of coercion. #> int(1) #> ^~~~~~ lint( text = \"as.character(NA)\", linters = literal_coercion_linter() ) #> :1:1: warning: [literal_coercion_linter] Use NA_character_ instead of as.character(NA), i.e., use literals directly where possible, instead of coercion. #> as.character(NA) #> ^~~~~~~~~~~~~~~~ lint( text = \"rlang::lgl(1L)\", linters = literal_coercion_linter() ) #> :1:1: warning: [literal_coercion_linter] Use TRUE instead of rlang::lgl(1L), i.e., use literals directly where possible, instead of coercion. #> rlang::lgl(1L) #> ^~~~~~~~~~~~~~ # 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/make_linter_from_xpath.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter from an XPath — make_linter_from_xpath","title":"Create a linter from an XPath — make_linter_from_xpath","text":"Create linter XPath","code":""},{"path":"https://lintr.r-lib.org/dev/reference/make_linter_from_xpath.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter from an XPath — make_linter_from_xpath","text":"","code":"make_linter_from_xpath( xpath, lint_message, type = c(\"warning\", \"style\", \"error\"), level = c(\"expression\", \"file\") ) make_linter_from_function_xpath( function_names, xpath, lint_message, type = c(\"warning\", \"style\", \"error\"), level = c(\"expression\", \"file\") )"},{"path":"https://lintr.r-lib.org/dev/reference/make_linter_from_xpath.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter from an XPath — make_linter_from_xpath","text":"xpath Character string, XPath identifying R code lint. make_linter_from_function_xpath(), XPath relative SYMBOL_FUNCTION_CALL nodes selected functions. See xmlparsedata::xml_parse_data() get_source_expressions(). lint_message message included message Lint object. lint_message character vector length xml, -th lint given -th message. type type lint. level level expression tested? \"expression\" means individual expression, \"file\" means expressions current file available. function_names Character vector, names functions whose calls examine..","code":""},{"path":"https://lintr.r-lib.org/dev/reference/make_linter_from_xpath.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter from an XPath — make_linter_from_xpath","text":"","code":"number_linter <- make_linter_from_xpath(\"//NUM_CONST\", \"This is a number.\") lint(text = \"1 + 2\", linters = number_linter()) #> :1:1: warning: [number_linter] This is a number. #> 1 + 2 #> ^ #> :1:5: warning: [number_linter] This is a number. #> 1 + 2 #> ^"},{"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() ) #> :1:1: warning: [matrix_apply_linter] Use rowSums(x) rather than apply(x, 1, sum) #> apply(x, 1, sum) #> ^~~~~~~~~~~~~~~~ lint( text = \"apply(x, 2, sum)\", linters = matrix_apply_linter() ) #> :1:1: warning: [matrix_apply_linter] Use rowSums(colSums(x)) or colSums(x) if x has 2 dimensions rather than apply(x, 2, sum) #> apply(x, 2, sum) #> ^~~~~~~~~~~~~~~~ lint( text = \"apply(x, 2, sum, na.rm = TRUE)\", linters = matrix_apply_linter() ) #> :1:1: warning: [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) #> apply(x, 2, sum, na.rm = TRUE) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"apply(x, 2:4, sum)\", linters = matrix_apply_linter() ) #> :1:1: warning: [matrix_apply_linter] Use rowSums(colSums(x), dims = 3) or colSums(x) if x has 4 dimensions rather than apply(x, 2:4, sum) #> 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() ) #> :1:17: style: [missing_argument_linter] Missing argument 2 in function call. #> tibble(x = \"a\", ) #> ^ # 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() ) #> :1:1: warning: [missing_package_linter] Package 'xyzxyz' is not installed. #> library(xyzxyz) #> ^~~~~~~~~~~~~~~ # 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\" \"structure\" \"Sys.setenv\" \"Sys.setlocale\" #> [21] \"trace\" \"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() ) #> :1:1: warning: [namespace_linter] Package 'xyzxyz' is not installed. #> xyzxyz::sd(c(1, 2, 3)) #> ^~~~~~ lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter() ) #> :1:8: warning: [namespace_linter] 'ssd' is not exported from {stats}. #> stats::ssd(c(1, 2, 3)) #> ^~~ # 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. say original code: ways avoid nesting make code readable: Use data.table::fcase() Use dplyr::case_match() Use look---merge approach (build mapping table values outputs merge input)","code":"ifelse( x == \"a\", 2L, ifelse(x == \"b\", 3L, 1L) ) data.table::fcase( x == \"a\", 2L, x == \"b\", 3L, default = 1L ) dplyr::case_match( x, \"a\" ~ 2L, \"b\" ~ 3L, .default = 1L ) default <- 1L values <- data.frame( a = 2L, b = 3L ) found_value <- values[[x]] ifelse(is.null(found_value), default, found_value)"},{"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() ) #> :1:22: warning: [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. #> ifelse(x == \"a\", 1L, ifelse(x == \"b\", 2L, 3L)) #> ^~~~~~~~~~~~~~~~~~~~~~~~ # 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/nested_pipe_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of pipes nested inside other calls — nested_pipe_linter","title":"Block usage of pipes nested inside other calls — nested_pipe_linter","text":"Nesting pipes harms readability; extract sub-steps separate variables, append pipeline steps, otherwise refactor usage away.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_pipe_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of pipes nested inside other calls — nested_pipe_linter","text":"","code":"nested_pipe_linter( allow_inline = TRUE, allow_outer_calls = c(\"try\", \"tryCatch\", \"withCallingHandlers\") )"},{"path":"https://lintr.r-lib.org/dev/reference/nested_pipe_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block usage of pipes nested inside other calls — nested_pipe_linter","text":"allow_inline Logical, default TRUE, case \"inner\" pipelines span one line linted. FALSE, even \"inner\" pipelines fit one line linted. allow_outer_calls Character vector dictating \"outer\" calls exempt requirement unnest (see examples). Defaults try(), tryCatch(), withCallingHandlers().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nested_pipe_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of pipes nested inside other calls — nested_pipe_linter","text":"configurable, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_pipe_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of pipes nested inside other calls — nested_pipe_linter","text":"","code":"# will produce lints code <- \"df1 %>%\\n inner_join(df2 %>%\\n select(a, b)\\n )\" writeLines(code) #> df1 %>% #> inner_join(df2 %>% #> select(a, b) #> ) lint( text = code, linters = nested_pipe_linter() ) #> :2:14: warning: [nested_pipe_linter] Don't nest pipes inside other calls. #> inner_join(df2 %>% #> ^~~~~~~ lint( text = \"df1 %>% inner_join(df2 %>% select(a, b))\", linters = nested_pipe_linter(allow_inline = FALSE) ) #> :1:20: warning: [nested_pipe_linter] Don't nest pipes inside other calls. #> df1 %>% inner_join(df2 %>% select(a, b)) #> ^~~~~~~~~~~~~~~~~~~~ lint( text = \"tryCatch(x %>% filter(grp == 'a'), error = identity)\", linters = nested_pipe_linter(allow_outer_calls = character()) ) # okay lint( text = \"df1 %>% inner_join(df2 %>% select(a, b))\", linters = nested_pipe_linter() ) code <- \"df1 %>%\\n inner_join(df2 %>%\\n select(a, b)\\n )\" writeLines(code) #> df1 %>% #> inner_join(df2 %>% #> select(a, b) #> ) lint( text = code, linters = nested_pipe_linter(allow_outer_calls = \"inner_join\") ) lint( text = \"tryCatch(x %>% filter(grp == 'a'), error = identity)\", linters = nested_pipe_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/nonportable_path_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Non-portable path linter — nonportable_path_linter","text":"","code":"# will produce lints lint( text = \"'abcdefg/hijklmnop/qrst/uv/wxyz'\", linters = nonportable_path_linter() ) #> :1:2: warning: [nonportable_path_linter] Use file.path() to construct portable file paths. #> 'abcdefg/hijklmnop/qrst/uv/wxyz' #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = \"file.path('abcdefg', 'hijklmnop', 'qrst', 'uv', 'wxyz')\", linters = nonportable_path_linter() )"},{"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/nrow_subset_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of nrow(subset(x, .)) — nrow_subset_linter","title":"Block usage of nrow(subset(x, .)) — nrow_subset_linter","text":"Using nrow(subset(x, condition)) count instances condition applies inefficiently requires full subset x just count number rows resulting subset. number equivalent expressions require full subset, e.g. (x, sum(condition)) (, generically, (x, sum(condition, na.rm = TRUE))).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nrow_subset_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of nrow(subset(x, .)) — nrow_subset_linter","text":"","code":"nrow_subset_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nrow_subset_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of nrow(subset(x, .)) — nrow_subset_linter","text":"best_practices, consistency, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nrow_subset_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of nrow(subset(x, .)) — nrow_subset_linter","text":"","code":"# will produce lints lint( text = \"nrow(subset(x, is_treatment))\", linters = nrow_subset_linter() ) #> :1:1: warning: [nrow_subset_linter] Use arithmetic to count the number of rows satisfying a condition, rather than fully subsetting the data.frame and counting the resulting rows. For example, replace nrow(subset(x, is_treatment)) with sum(x$is_treatment). NB: use na.rm = TRUE if `is_treatment` has missing values. #> nrow(subset(x, is_treatment)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"nrow(filter(x, is_treatment))\", linters = nrow_subset_linter() ) #> :1:1: warning: [nrow_subset_linter] Use arithmetic to count the number of rows satisfying a condition, rather than fully subsetting the data.frame and counting the resulting rows. For example, replace nrow(subset(x, is_treatment)) with sum(x$is_treatment). NB: use na.rm = TRUE if `is_treatment` has missing values. #> nrow(filter(x, is_treatment)) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = \"x %>% filter(x, is_treatment) %>% nrow()\", linters = nrow_subset_linter() ) #> :1:1: warning: [nrow_subset_linter] Use arithmetic to count the number of rows satisfying a condition, rather than fully subsetting the data.frame and counting the resulting rows. For example, replace nrow(subset(x, is_treatment)) with sum(x$is_treatment). NB: use na.rm = TRUE if `is_treatment` has missing values. #> x %>% filter(x, is_treatment) %>% nrow() #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = \"with(x, sum(is_treatment, na.rm = TRUE))\", linters = nrow_subset_linter() )"},{"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() ) #> :1:6: warning: [numeric_leading_zero_linter] Include the leading zero for fractional numeric constants. #> x <- .1 #> ^~ lint( text = \"x <- -.1\", linters = numeric_leading_zero_linter() ) #> :1:7: warning: [numeric_leading_zero_linter] Include the leading zero for fractional numeric constants. #> x <- -.1 #> ^~ # okay lint( text = \"x <- 0.1\", linters = numeric_leading_zero_linter() ) lint( text = \"x <- -0.1\", linters = numeric_leading_zero_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/nzchar_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of nzchar where appropriate — nzchar_linter","title":"Require usage of nzchar where appropriate — nzchar_linter","text":"nzchar() efficiently determines vector strings empty (.e., \"\"). cases used instead constructions like string == \"\" nchar(string) == 0.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nzchar_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of nzchar where appropriate — nzchar_linter","text":"","code":"nzchar_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/nzchar_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of nzchar where appropriate — nzchar_linter","text":"One crucial difference default handling NA_character_, .e., missing strings. nzchar(NA_character_) TRUE, NA_character_ == \"\" nchar(NA_character_) == 0 NA. Therefore, strict compatibility, use nzchar(x, keepNA = TRUE). input known complete (missing entries), argument can dropped conciseness.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nzchar_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of nzchar where appropriate — nzchar_linter","text":"best_practices, consistency, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nzchar_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of nzchar where appropriate — nzchar_linter","text":"","code":"# will produce lints lint( text = \"x[x == '']\", linters = nzchar_linter() ) #> :1:3: warning: [nzchar_linter] Use !nzchar(x) instead of x == \"\". Note that unlike nzchar(), EQ coerces to character, so you'll have to use as.character() if x is a factor. Whenever missing data is possible, please take care to use nzchar(., keepNA = TRUE); nzchar(NA) is TRUE by default. #> x[x == ''] #> ^~~~~~~ lint( text = \"x[nchar(x) > 0]\", linters = nzchar_linter() ) #> :1:3: warning: [nzchar_linter] Use nzchar(x) instead of nchar(x) > 0. Whenever missing data is possible, please take care to use nzchar(., keepNA = TRUE); nzchar(NA) is TRUE by default. #> x[nchar(x) > 0] #> ^~~~~~~~~~~~ # okay lint( text = \"x[!nzchar(x, keepNA = TRUE)]\", linters = nzchar_linter() ) lint( text = \"x[nzchar(x, keepNA = TRUE)]\", linters = nzchar_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/object_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Object length linter — object_length_linter","title":"Object length linter — object_length_linter","text":"Check object names long. length object name defined length characters, removing extraneous parts:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Object length linter — object_length_linter","text":"","code":"object_length_linter(length = 30L)"},{"path":"https://lintr.r-lib.org/dev/reference/object_length_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Object length linter — object_length_linter","text":"length maximum variable name length allowed.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_length_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Object length linter — object_length_linter","text":"generic prefixes implementations S3 generics, e.g. .data.frame.my_class length 8. leading ., e.g. .my_hidden_function length 18. \"%%\" infix operators, e.g. %my_op% length 5. trailing <- assignment functions, e.g. my_attr<- length 7. Note behavior relies part packages Imports available; see detailed note object_name_linter() details.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/object_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Object length linter — object_length_linter","text":"configurable, default, executing, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Object length linter — object_length_linter","text":"","code":"# will produce lints lint( text = \"very_very_long_variable_name <- 1L\", linters = object_length_linter(length = 10L) ) #> :1:1: style: [object_length_linter] Variable and function names should not be longer than 10 characters. #> very_very_long_variable_name <- 1L #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = \"very_very_long_variable_name <- 1L\", linters = object_length_linter(length = 30L) ) lint( text = \"var <- 1L\", linters = object_length_linter(length = 10L) )"},{"path":"https://lintr.r-lib.org/dev/reference/object_name_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Object name linter — object_name_linter","title":"Object name linter — object_name_linter","text":"Check object names conform naming style. default naming styles \"snake_case\" \"symbols\".","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_name_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Object name linter — object_name_linter","text":"","code":"object_name_linter(styles = c(\"snake_case\", \"symbols\"), regexes = character())"},{"path":"https://lintr.r-lib.org/dev/reference/object_name_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Object name linter — object_name_linter","text":"styles subset ‘symbols’, ‘CamelCase’, ‘camelCase’, ‘snake_case’, ‘SNAKE_CASE’, ‘dotted.case’, ‘lowercase’, ‘UPPERCASE’ . name match least one styles. \"symbols\" style refers names containing non-alphanumeric characters; e.g., defining %+% ggplot2 %>% magrittr generate lint markers, whereas %m+% lubridate (containing alphanumeric non-alphanumeric characters) . regexes (possibly named) character vector specifying custom naming convention. named, names used lint message. Otherwise, regexes enclosed / used lint message. Note specifying regexes overrides default styles. want combine regexes styles, need explicitly specified.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_name_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Object name linter — object_name_linter","text":"Quotes (`\"') specials (% trailing <-) considered part object name. Note used package, order ignore objects imported namespaces, linter attempt getNamespaceExports() whenever import(PKG) importFrom(PKG, ...) statement found NAMESPACE file. requireNamespace() fails (e.g., package yet installed), linter able ignore usages otherwise allowed. Suppose, example, import(upstream) NAMESPACE, makes available exported S3 generic function a_really_quite_long_function_name extend package defining corresponding method class my_class. , upstream installed linter runs, lint thrown object (even though \"\" full name). best way get lintr work correctly install package available session linter running.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/object_name_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Object name linter — object_name_linter","text":"configurable, consistency, default, executing, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_name_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Object name linter — object_name_linter","text":"","code":"# will produce lints lint( text = \"my_var <- 1L\", linters = object_name_linter(styles = \"CamelCase\") ) #> :1:1: style: [object_name_linter] Variable and function name style should match CamelCase. #> my_var <- 1L #> ^~~~~~ lint( text = \"xYz <- 1L\", linters = object_name_linter(styles = c(\"UPPERCASE\", \"lowercase\")) ) #> :1:1: style: [object_name_linter] Variable and function name style should match UPPERCASE or lowercase. #> xYz <- 1L #> ^~~ lint( text = \"MyVar <- 1L\", linters = object_name_linter(styles = \"dotted.case\") ) #> :1:1: style: [object_name_linter] Variable and function name style should match dotted.case. #> MyVar <- 1L #> ^~~~~ lint( text = \"asd <- 1L\", linters = object_name_linter(regexes = c(my_style = \"F$\", \"f$\")) ) #> :1:1: style: [object_name_linter] Variable and function name style should match my_style or /f$/. #> asd <- 1L #> ^~~ # okay lint( text = \"my_var <- 1L\", linters = object_name_linter(styles = \"snake_case\") ) lint( text = \"xyz <- 1L\", linters = object_name_linter(styles = \"lowercase\") ) lint( text = \"my.var <- 1L; myvar <- 2L\", linters = object_name_linter(styles = c(\"dotted.case\", \"lowercase\")) ) lint( text = \"asdf <- 1L; asdF <- 1L\", linters = object_name_linter(regexes = c(my_style = \"F$\", \"f$\")) )"},{"path":"https://lintr.r-lib.org/dev/reference/object_overwrite_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block assigning any variables whose name clashes with a base R function — object_overwrite_linter","title":"Block assigning any variables whose name clashes with a base R function — object_overwrite_linter","text":"Re-using existing names creates risk subtle error best avoided. Avoiding practice also encourages using better, descriptive names.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_overwrite_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block assigning any variables whose name clashes with a base R function — object_overwrite_linter","text":"","code":"object_overwrite_linter( packages = c(\"base\", \"stats\", \"utils\", \"tools\", \"methods\", \"graphics\", \"grDevices\"), allow_names = character() )"},{"path":"https://lintr.r-lib.org/dev/reference/object_overwrite_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block assigning any variables whose name clashes with a base R function — object_overwrite_linter","text":"packages Character vector packages search names avoided. Defaults common default packages: base, stats, utils, tools, methods, graphics, grDevices. allow_names Character vector object names ignore, .e., allowed collide exports packages.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/object_overwrite_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block assigning any variables whose name clashes with a base R function — object_overwrite_linter","text":"best_practices, configurable, executing, readability, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_overwrite_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block assigning any variables whose name clashes with a base R function — object_overwrite_linter","text":"","code":"# will produce lints code <- \"function(x) {\\n data <- x\\n data\\n}\" writeLines(code) #> function(x) { #> data <- x #> data #> } lint( text = code, linters = object_overwrite_linter() ) #> :2:3: warning: [object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols. #> data <- x #> ^~~~ code <- \"function(x) {\\n lint <- 'fun'\\n lint\\n}\" writeLines(code) #> function(x) { #> lint <- 'fun' #> lint #> } lint( text = code, linters = object_overwrite_linter(packages = \"lintr\") ) #> :2:3: warning: [object_overwrite_linter] 'lint' is an exported object from package 'lintr'. Avoid re-using such symbols. #> lint <- 'fun' #> ^~~~ # okay code <- \"function(x) {\\n data('mtcars')\\n}\" writeLines(code) #> function(x) { #> data('mtcars') #> } lint( text = code, linters = object_overwrite_linter() ) code <- \"function(x) {\\n data <- x\\n data\\n}\" writeLines(code) #> function(x) { #> data <- x #> data #> } lint( text = code, linters = object_overwrite_linter(packages = \"base\") ) # names in function signatures are ignored lint( text = \"function(data) data <- subset(data, x > 0)\", linters = object_overwrite_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/object_usage_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Object usage linter — object_usage_linter","title":"Object usage linter — object_usage_linter","text":"Check closures proper usage using codetools::checkUsage(). Note runs base::eval() code, use untrusted code.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_usage_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Object usage linter — object_usage_linter","text":"","code":"object_usage_linter(interpret_glue = TRUE, skip_with = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/object_usage_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Object usage linter — object_usage_linter","text":"interpret_glue TRUE, interpret glue::glue() calls avoid false positives caused local variables used glue expression. skip_with logical. TRUE (default), code () expressions skipped. argument passed skipWith argument codetools::checkUsage().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/object_usage_linter.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Object usage linter — object_usage_linter","text":"following linters tagged 'package_development': backport_linter conjunct_test_linter expect_comparison_linter expect_identical_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 package_hooks_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/object_usage_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Object usage linter — object_usage_linter","text":"","code":"# will produce lints lint( text = \"foo <- function() { x <- 1 }\", linters = object_usage_linter() ) #> :1:21: warning: [object_usage_linter] local variable 'x' assigned but may not be used #> foo <- function() { x <- 1 } #> ^ # okay lint( text = \"foo <- function(x) { x <- 1 }\", linters = object_usage_linter() ) lint( text = \"foo <- function() { x <- 1; return(x) }\", linters = object_usage_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/one_call_pipe_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block single-call magrittr pipes — one_call_pipe_linter","title":"Block single-call magrittr pipes — one_call_pipe_linter","text":"Prefer using plain call instead pipe one call, .e. 1:10 %>% sum() instead sum(1:10). Note calls first %>% argument count. rowSums(x) %>% max() OK two total calls (rowSums() max()).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/one_call_pipe_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block single-call magrittr pipes — one_call_pipe_linter","text":"","code":"one_call_pipe_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/one_call_pipe_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block single-call magrittr pipes — one_call_pipe_linter","text":"Note also un-\"called\" steps counted, since calls (see pipe_call_linter()).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/one_call_pipe_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block single-call magrittr pipes — one_call_pipe_linter","text":"readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/one_call_pipe_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block single-call magrittr pipes — one_call_pipe_linter","text":"","code":"# will produce lints lint( text = \"(1:10) %>% sum()\", linters = one_call_pipe_linter() ) #> :1:1: warning: [one_call_pipe_linter] Avoid pipe %>% for expressions with only a single call. #> (1:10) %>% sum() #> ^~~~~~~~~~~~~~~~ lint( text = \"DT %>% .[grp == 'a', sum(v)]\", linters = one_call_pipe_linter() ) #> :1:1: warning: [one_call_pipe_linter] Avoid pipe %>% for expressions with only a single call. #> DT %>% .[grp == 'a', sum(v)] #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = \"rowSums(x) %>% mean()\", linters = one_call_pipe_linter() ) lint( text = \"DT[src == 'a', .N, by = grp] %>% .[N > 10]\", linters = one_call_pipe_linter() ) # assignment pipe is exempted lint( text = \"DF %<>% mutate(a = 2)\", linters = one_call_pipe_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/outer_negation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of !any(x) over all(!x), !all(x) over any(!x) — outer_negation_linter","title":"Require usage of !any(x) over all(!x), !all(x) over any(!x) — outer_negation_linter","text":"(!x) logically equivalent !(x); ditto equivalence (!x) !(x). Negating aggregation requires inverting one logical value, typically readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/outer_negation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of !any(x) over all(!x), !all(x) over any(!x) — outer_negation_linter","text":"","code":"outer_negation_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/outer_negation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of !any(x) over all(!x), !all(x) over any(!x) — outer_negation_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/outer_negation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of !any(x) over all(!x), !all(x) over any(!x) — outer_negation_linter","text":"","code":"# will produce lints lint( text = \"all(!x)\", linters = outer_negation_linter() ) #> :1:1: warning: [outer_negation_linter] !any(x) is better than all(!x). The former applies negation only once after aggregation instead of many times for each element of x. #> all(!x) #> ^~~~~~~ lint( text = \"any(!x)\", linters = outer_negation_linter() ) #> :1:1: warning: [outer_negation_linter] !all(x) is better than any(!x). The former applies negation only once after aggregation instead of many times for each element of x. #> any(!x) #> ^~~~~~~ # okay lint( text = \"!any(x)\", linters = outer_negation_linter() ) lint( text = \"!all(x)\", linters = outer_negation_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/package_development_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Package development linters — package_development_linters","title":"Package development linters — package_development_linters","text":"Linters useful package developers, example writing consistent tests.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/package_development_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Package development linters — package_development_linters","text":"following linters tagged 'package_development': backport_linter conjunct_test_linter expect_comparison_linter expect_identical_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 package_hooks_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/package_hooks_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Package hooks linter — package_hooks_linter","title":"Package hooks linter — package_hooks_linter","text":"Check various common \"gotchas\" .onLoad(), .onAttach(), .Last.lib(), .onDetach() namespace hooks cause R CMD check issues. See Writing R Extensions details.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/package_hooks_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Package hooks linter — package_hooks_linter","text":"","code":"package_hooks_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/package_hooks_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Package hooks linter — package_hooks_linter","text":".onLoad() call cat(), message(), print(), writeLines(), packageStartupMessage(), require(), library(), installed.packages(). .onAttach() call cat(), message(), print(), writeLines(), library.dynam(), require(), library(), installed.packages(). .Last.lib() .onDetach() call library.dynam.unload(). .onLoad() .onAttach() take two arguments, names matching ^lib ^pkg; .Last.lib() .onDetach() take one argument name matching ^lib.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/package_hooks_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Package hooks linter — package_hooks_linter","text":"correctness, package_development, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/package_hooks_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Package hooks linter — package_hooks_linter","text":"","code":"# will produce lints lint( text = \".onLoad <- function(lib, ...) { }\", linters = package_hooks_linter() ) #> :1:12: warning: [package_hooks_linter] .onLoad() should take two arguments, with the first starting with 'lib' and the second starting with 'pkg'. #> .onLoad <- function(lib, ...) { } #> ^~~~~~~~~~~~~~~~~~~~~~ lint( text = \".onAttach <- function(lib, pkg) { require(foo) }\", linters = package_hooks_linter() ) #> :1:35: warning: [package_hooks_linter] Don't alter the search() path in .onAttach() by calling require(). #> .onAttach <- function(lib, pkg) { require(foo) } #> ^~~~~~~ lint( text = \".onDetach <- function(pkg) { }\", linters = package_hooks_linter() ) #> :1:14: warning: [package_hooks_linter] .onDetach() should take one argument starting with 'lib'. #> .onDetach <- function(pkg) { } #> ^~~~~~~~~~~~~~~~~ # okay lint( text = \".onLoad <- function(lib, pkg) { }\", linters = package_hooks_linter() ) lint( text = '.onAttach <- function(lib, pkg) { loadNamespace(\"foo\") }', linters = package_hooks_linter() ) lint( text = \".onDetach <- function(lib) { }\", linters = package_hooks_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/paren_body_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Parenthesis before body linter — paren_body_linter","title":"Parenthesis before body linter — paren_body_linter","text":"Check space right parenthesis body expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/paren_body_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Parenthesis before body linter — paren_body_linter","text":"","code":"paren_body_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/paren_body_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Parenthesis before body linter — paren_body_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/paren_body_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Parenthesis before body linter — paren_body_linter","text":"","code":"# will produce lints lint( text = \"function(x)x + 1\", linters = paren_body_linter() ) #> :1:12: style: [paren_body_linter] Put a space between a right parenthesis and a body expression. #> function(x)x + 1 #> ^~~~~ # okay lint( text = \"function(x) x + 1\", linters = paren_body_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/parse_exclusions.html","id":null,"dir":"Reference","previous_headings":"","what":"read a source file and parse all the excluded lines from it — parse_exclusions","title":"read a source file and parse all the excluded lines from it — parse_exclusions","text":"read source file parse excluded lines ","code":""},{"path":"https://lintr.r-lib.org/dev/reference/parse_exclusions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"read a source file and parse all the excluded lines from it — parse_exclusions","text":"","code":"parse_exclusions( file, exclude = settings$exclude, exclude_next = settings$exclude_next, exclude_start = settings$exclude_start, exclude_end = settings$exclude_end, exclude_linter = settings$exclude_linter, exclude_linter_sep = settings$exclude_linter_sep, lines = NULL, linter_names = NULL )"},{"path":"https://lintr.r-lib.org/dev/reference/parse_exclusions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"read a source file and parse all the excluded lines from it — parse_exclusions","text":"file R source file exclude Regular expression used mark lines exclude. exclude_next Regular expression used mark lines immediately preceding excluded lines. exclude_start Regular expression used mark start excluded range. exclude_end Regular expression used mark end excluded range. exclude_linter Regular expression used capture list --excluded linters immediately following exclude exclude_start marker. exclude_linter_sep Regular expression used split linter list individual linter names exclusion. lines character vector content lines file. linter_names Names active linters.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/parse_exclusions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"read a source file and parse all the excluded lines from it — parse_exclusions","text":"possibly named list excluded lines, possibly specific linters.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/paste_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Raise lints for several common poor usages of paste() — paste_linter","title":"Raise lints for several common poor usages of paste() — paste_linter","text":"following issues linted default linter (see arguments can de-activated optionally): Block usage paste() sep = \"\". paste0() faster, concise alternative. Block usage paste() paste0() collapse = \", \". toString() direct wrapper , alternatives like glue::glue_collapse() might give better messages humans. Block usage paste0() supplies sep= – formal argument paste0, likely mistake. Block usage paste() / paste0() combined rep() replaced strrep(). strrep() can handle task building block repeated strings (e.g. often used build \"horizontal lines\" messages). readable skips (likely small) overhead putting two strings global string cache one needed. target scalar usages – strrep can handle complicated cases (e.g. strrep(letters, 26:1), easily translated paste(collapse=) call.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/paste_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Raise lints for several common poor usages of paste() — paste_linter","text":"","code":"paste_linter( allow_empty_sep = FALSE, allow_to_string = FALSE, allow_file_path = c(\"double_slash\", \"always\", \"never\") )"},{"path":"https://lintr.r-lib.org/dev/reference/paste_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Raise lints for several common poor usages of paste() — paste_linter","text":"allow_empty_sep Logical, default FALSE. TRUE, usage paste() sep = \"\" linted. allow_to_string Logical, default FALSE. TRUE, usage paste() paste0() collapse = \", \" linted. allow_file_path String, one \"never\", \"double_slash\", \"always\"; \"double_slash\" default. \"never\", usage paste() paste0() construct file paths linted. \"double_slash\", strings containing consecutive forward slashes lint. main use case URLs – \"paths\" like \"https://\" induce lints, since constructing file.path() might deemed unnatural. Lastly, \"always\", strings consecutive forward slashes also lint. Note \"//\" never linted comes beginning end input, avoid requiring empty inputs like file.path(\"\", ...) file.path(..., \"\").","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/paste_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Raise lints for several common poor usages of paste() — paste_linter","text":"best_practices, configurable, consistency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/paste_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Raise lints for several common poor usages of paste() — paste_linter","text":"","code":"# will produce lints lint( text = 'paste(\"a\", \"b\", sep = \"\")', linters = paste_linter() ) #> :1:1: warning: [paste_linter] paste0(...) is better than paste(..., sep = \"\"). #> paste(\"a\", \"b\", sep = \"\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'paste(c(\"a\", \"b\"), collapse = \", \")', linters = paste_linter() ) #> :1:1: warning: [paste_linter] toString(.) is more expressive than paste(., collapse = \", \"). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists #> paste(c(\"a\", \"b\"), collapse = \", \") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'paste0(c(\"a\", \"b\"), sep = \" \")', linters = paste_linter() ) #> :1:1: warning: [paste_linter] sep= is not a formal argument to paste0(); did you mean to use paste(), or collapse=? #> paste0(c(\"a\", \"b\"), sep = \" \") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'paste0(rep(\"*\", 10L), collapse = \"\")', linters = paste_linter() ) #> :1:1: warning: [paste_linter] strrep(x, times) is better than paste0(rep(x, times), collapse = \"\"). #> paste0(rep(\"*\", 10L), collapse = \"\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #> :1:1: warning: [paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used. #> paste0(rep(\"*\", 10L), collapse = \"\") #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'paste0(\"http://site.com/\", path)', linters = paste_linter(allow_file_path = \"never\") ) #> :1:1: warning: [paste_linter] Construct file paths with file.path(...) instead of paste0(x, \"/\", y, \"/\", z). Note that paste() converts empty inputs to \"\", whereas file.path() leaves it empty. #> paste0(\"http://site.com/\", path) #> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lint( text = 'paste0(x, collapse = \"\")', linters = paste_linter() ) #> :1:1: warning: [paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used. #> paste0(x, collapse = \"\") #> ^~~~~~~~~~~~~~~~~~~~~~~~ # okay lint( text = 'paste0(\"a\", \"b\")', linters = paste_linter() ) lint( text = 'paste(\"a\", \"b\", sep = \"\")', linters = paste_linter(allow_empty_sep = TRUE) ) lint( text = 'toString(c(\"a\", \"b\"))', linters = paste_linter() ) lint( text = 'paste(c(\"a\", \"b\"), collapse = \", \")', linters = paste_linter(allow_to_string = TRUE) ) lint( text = 'paste(c(\"a\", \"b\"))', linters = paste_linter() ) lint( text = 'strrep(\"*\", 10L)', linters = paste_linter() ) lint( text = 'paste0(year, \"/\", month, \"/\", day)', linters = paste_linter(allow_file_path = \"always\") ) lint( text = 'paste0(\"http://site.com/\", path)', linters = paste_linter() ) lint( text = 'paste(x, collapse = \"\")', linters = paste_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/pipe_call_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe call linter — pipe_call_linter","title":"Pipe call linter — pipe_call_linter","text":"Force explicit calls magrittr pipes, e.g., 1:3 %>% sum() instead 1:3 %>% sum. Note native pipe always requires function call, .e. 1:3 |> sum produce error.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_call_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe call linter — pipe_call_linter","text":"","code":"pipe_call_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/pipe_call_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Pipe call linter — pipe_call_linter","text":"readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_call_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pipe call linter — pipe_call_linter","text":"","code":"# will produce lints lint( text = \"1:3 %>% mean %>% as.character\", linters = pipe_call_linter() ) #> :1:9: warning: [pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`. #> 1:3 %>% mean %>% as.character #> ^~~~ #> :1:18: warning: [pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`. #> 1:3 %>% mean %>% as.character #> ^~~~~~~~~~~~ # okay lint( text = \"1:3 %>% mean() %>% as.character()\", linters = pipe_call_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/pipe_consistency_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe consistency linter — pipe_consistency_linter","title":"Pipe consistency linter — pipe_consistency_linter","text":"Check pipe operators used consistently file, optionally specify one valid pipe operator.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_consistency_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe consistency linter — pipe_consistency_linter","text":"","code":"pipe_consistency_linter(pipe = c(\"auto\", \"%>%\", \"|>\"))"},{"path":"https://lintr.r-lib.org/dev/reference/pipe_consistency_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pipe consistency linter — pipe_consistency_linter","text":"pipe pipe operator valid (either \"%>%\" \"|>\"). default (\"auto\"), linter preference check file uses one type pipe operator.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/pipe_consistency_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Pipe consistency linter — pipe_consistency_linter","text":"configurable, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_consistency_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pipe consistency linter — pipe_consistency_linter","text":"","code":"# will produce lints lint( text = \"1:3 |> mean() %>% as.character()\", linters = pipe_consistency_linter() ) #> :1:5: style: [pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>. #> 1:3 |> mean() %>% as.character() #> ^~ #> :1:15: style: [pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>. #> 1:3 |> mean() %>% as.character() #> ^~~ lint( text = \"1:3 %>% mean() %>% as.character()\", linters = pipe_consistency_linter(\"|>\") ) #> :1:5: style: [pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator. #> 1:3 %>% mean() %>% as.character() #> ^~~ #> :1:16: style: [pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator. #> 1:3 %>% mean() %>% as.character() #> ^~~ # okay lint( text = \"1:3 %>% mean() %>% as.character()\", linters = pipe_consistency_linter() ) lint( text = \"1:3 |> mean() |> as.character()\", linters = pipe_consistency_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/pipe_continuation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe continuation linter — pipe_continuation_linter","title":"Pipe continuation linter — pipe_continuation_linter","text":"Check step pipeline new line, entire pipe fits one line.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_continuation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe continuation linter — pipe_continuation_linter","text":"","code":"pipe_continuation_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/pipe_continuation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Pipe continuation linter — pipe_continuation_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_continuation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pipe continuation linter — pipe_continuation_linter","text":"","code":"# will produce lints code_lines <- \"1:3 %>%\\n mean() %>% as.character()\" writeLines(code_lines) #> 1:3 %>% #> mean() %>% as.character() lint( text = code_lines, linters = pipe_continuation_linter() ) #>