diff --git a/dev/articles/creating_linters.html b/dev/articles/creating_linters.html index dc05373cc..bace5dce8 100644 --- a/dev/articles/creating_linters.html +++ b/dev/articles/creating_linters.html @@ -87,7 +87,7 @@

lintr maintainers

-

2024-06-13

+

2024-06-15

Source: vignettes/creating_linters.Rmd
creating_linters.Rmd
diff --git a/dev/news/index.html b/dev/news/index.html index 22cc4117e..3a962bc32 100644 --- a/dev/news/index.html +++ b/dev/news/index.html @@ -793,7 +793,7 @@
Google lintersexpect_type_linter() Require usage of expect_type(x, t) over expect_equal(typeof(x), t) and similar.
  • -fixed_regex_linter() Require fixed = TRUE or stringr::fixed() for regular expressions that can be expressed statically, e.g. strsplit(x, "[.]") can be strsplit(x, ".", fixed = TRUE). +fixed_regex_linter() Require fixed = TRUE or stringr::fixed() for regular expressions that can be expressed statically, e.g. strsplit(x, "[.]") can be strsplit(x, ".", fixed = TRUE).
  • diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index 3cad9cfb4..0b021fb21 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-06-13T06:08Z +last_built: 2024-06-15T06:35Z urls: reference: https://lintr.r-lib.org/reference article: https://lintr.r-lib.org/articles diff --git a/dev/reference/fixed_regex_linter.html b/dev/reference/fixed_regex_linter.html index f593b6c2f..2a41caff8 100644 --- a/dev/reference/fixed_regex_linter.html +++ b/dev/reference/fixed_regex_linter.html @@ -83,7 +83,7 @@

    Arguments

    Details

    -

    NB: for stringr functions, that means wrapping the pattern in stringr::fixed().

    +

    NB: for stringr functions, that means wrapping the pattern in stringr::fixed().

    NB: this linter is likely not able to distinguish every possible case when a fixed regular expression is preferable, rather it seeks to identify likely cases. It should never report false positives, however; please diff --git a/dev/reference/get_source_expressions.html b/dev/reference/get_source_expressions.html index 6fcc29e7d..1c5e81e79 100644 --- a/dev/reference/get_source_expressions.html +++ b/dev/reference/get_source_expressions.html @@ -140,7 +140,7 @@

    Examples#> $expressions #> $expressions[[1]] #> $expressions[[1]]$filename -#> [1] "/tmp/RtmpULBwEU/file16ca65cad61a" +#> [1] "/tmp/RtmpgA7L92/file17c117be6fee" #> #> $expressions[[1]]$line #> [1] 1 @@ -180,8 +180,8 @@

    Examples#> res #> else unname(res) #> } -#> <bytecode: 0x56055dbc4a28> -#> <environment: 0x56055cfdf498> +#> <bytecode: 0x562dae104d88> +#> <environment: 0x562dad805cb0> #> #> $expressions[[1]]$content #> [1] "x <- 1" @@ -189,7 +189,7 @@

    Examples#> #> $expressions[[2]] #> $expressions[[2]]$filename -#> [1] "/tmp/RtmpULBwEU/file16ca65cad61a" +#> [1] "/tmp/RtmpgA7L92/file17c117be6fee" #> #> $expressions[[2]]$line #> [1] 2 @@ -233,8 +233,8 @@

    Examples#> res #> else unname(res) #> } -#> <bytecode: 0x56055dbc4a28> -#> <environment: 0x56055cfe25b8> +#> <bytecode: 0x562dae104d88> +#> <environment: 0x562dad808af8> #> #> $expressions[[2]]$content #> [1] "y <- x + 1" @@ -242,7 +242,7 @@

    Examples#> #> $expressions[[3]] #> $expressions[[3]]$filename -#> [1] "/tmp/RtmpULBwEU/file16ca65cad61a" +#> [1] "/tmp/RtmpgA7L92/file17c117be6fee" #> #> $expressions[[3]]$file_lines #> 1 2 @@ -295,8 +295,8 @@

    Examples#> res #> else unname(res) #> } -#> <bytecode: 0x56055dbc4a28> -#> <environment: 0x56055cfd9658> +#> <bytecode: 0x562dae104d88> +#> <environment: 0x562dad8303f8> #> #> $expressions[[3]]$terminal_newline #> [1] TRUE diff --git a/dev/reference/lint.html b/dev/reference/lint.html index 56f6863d1..d278f7d9b 100644 --- a/dev/reference/lint.html +++ b/dev/reference/lint.html @@ -192,8 +192,8 @@

    Examples
    f <- tempfile()
     writeLines("a=1", f)
     lint(f)                # linting a file
    -#> ::warning file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2::file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2,[assignment_linter] Use <-, not =, for assignment.
    -#> ::warning file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2::file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators.
    +#> ::warning file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2::file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2,[assignment_linter] Use <-, not =, for assignment.
    +#> ::warning file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2::file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators.
     lint("a = 123\n")      # linting inline-code
     #> ::warning file=<text>,line=1,col=3::file=<text>,line=1,col=3,[assignment_linter] Use <-, not =, for assignment.
     lint(text = "a = 123") # linting inline-code
    diff --git a/dev/reference/trailing_blank_lines_linter.html b/dev/reference/trailing_blank_lines_linter.html
    index a7709933a..cbfecba02 100644
    --- a/dev/reference/trailing_blank_lines_linter.html
    +++ b/dev/reference/trailing_blank_lines_linter.html
    @@ -93,7 +93,7 @@ 

    Examples filename = f, linters = trailing_blank_lines_linter() ) -#> ::warning file=/tmp/RtmpULBwEU/file16ca5fec15a,line=2,col=1::file=/tmp/RtmpULBwEU/file16ca5fec15a,line=2,col=1,[trailing_blank_lines_linter] Remove trailing blank lines. +#> ::warning file=/tmp/RtmpgA7L92/file17c14a8324c6,line=2,col=1::file=/tmp/RtmpgA7L92/file17c14a8324c6,line=2,col=1,[trailing_blank_lines_linter] Remove trailing blank lines. unlink(f) # okay diff --git a/dev/search.json b/dev/search.json index fcc85dc72..33a6d6520 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. #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 81 characters. X = 42L # nolint ------ this comment overflows the default 80 chars line length."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-only-some-linters","dir":"Articles","previous_headings":"Exclusions","what":"Excluding only some linters","title":"Using lintr","text":"file3.R > lint(\"file3.R\") Observe object_name_linter suppressed. preferable blanket # nolint statements blanket exclusions may accidentally silence linter intentionally suppressed. Multiple linters can specified listing comma separator: file4.R > lint(\"file4.R\") can also specify linter names unique prefix instead full name: file5.R > lint(\"file5.R\")","code":"X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 94 characters. X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-multiple-lines-of-codes","dir":"Articles","previous_headings":"Exclusions","what":"Excluding multiple lines of codes","title":"Using lintr","text":"linters disabled contiguous block code, exclude_start exclude_end patterns can used. default # nolint start # nolint end respectively. # nolint start accepts syntax # nolint disable specific linters following lines # nolint end encountered. (lints)","code":"# x <- 42L # print(x) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Remove commented code. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[commented_code_linter] Remove commented code. # 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() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[T_and_F_symbol_linter] Use TRUE instead of the symbol T. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[T_and_F_symbol_linter] Use FALSE instead of the symbol F. lint( text = \"T = 1.2; F = 2.4\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[T_and_F_symbol_linter] Don't use T as a variable name, as it can break code relying on T being TRUE. #> ::warning file=,line=1,col=11::file=,line=1,col=11,[T_and_F_symbol_linter] Don't use F as a variable name, as it can break code relying on F being FALSE. # okay lint( text = \"x <- c(TRUE, FALSE)\", linters = T_and_F_symbol_linter() ) lint( text = \"t = 1.2; f = 2.4\", linters = T_and_F_symbol_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Absolute path linter — absolute_path_linter","title":"Absolute path linter — absolute_path_linter","text":"Check absolute paths used (e.g. \"/var\", \"C:\\System\", \"~/docs\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Absolute path linter — absolute_path_linter","text":"","code":"absolute_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Absolute path linter — absolute_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Absolute path linter — absolute_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Absolute path linter — absolute_path_linter","text":"","code":"# will produce lints lint( text = 'R\"--[/blah/file.txt]--\"', linters = absolute_path_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[absolute_path_linter] Do not use absolute paths. # okay lint( text = 'R\"(./blah)\"', linters = absolute_path_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on all available linters — all_linters","title":"Create a linter configuration based on all available linters — all_linters","text":"Create linter configuration based available linters","code":""},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"all_linters(..., packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on all available linters — all_linters","text":"... 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). lint( text = \"length(unique(x)) == length(x)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). # okay lint( text = \"anyDuplicated(x)\", linters = any_duplicated_linter() ) lint( text = \"anyDuplicated(x) == 0L\", linters = any_duplicated_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"anyNA() exists replacement (.na(x)) efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"any_is_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"# will produce lints lint( text = \"any(is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). lint( text = \"any(is.na(foo(x)))\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). # okay lint( text = \"anyNA(x)\", linters = any_is_na_linter() ) lint( text = \"anyNA(foo(x))\", linters = any_is_na_linter() ) lint( text = \"any(!is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Assignment linter — assignment_linter","title":"Assignment linter — assignment_linter","text":"Check <- always used assignment.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assignment linter — assignment_linter","text":"","code":"assignment_linter( allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE, allow_pipe_assign = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Assignment linter — assignment_linter","text":"allow_cascading_assign Logical, default TRUE. FALSE, <<- ->> allowed. allow_right_assign Logical, default FALSE. TRUE, -> ->> allowed. allow_trailing Logical, default TRUE. FALSE assignments allowed end lines. allow_pipe_assign Logical, default FALSE. TRUE, magrittr's %<>% assignment allowed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Assignment linter — assignment_linter","text":"configurable, consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Assignment linter — assignment_linter","text":"","code":"# will produce lints lint( text = \"x = mean(x)\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not ->, for assignment. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[assignment_linter] Replace ->> by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. lint( text = \"x %<>% as.character()\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Avoid the assignment pipe %<>%; prefer using <- and %>% separately. # okay lint( text = \"x <- mean(x)\", linters = assignment_linter() ) code_lines <- \"x <- 1\\ny <<- 2\" writeLines(code_lines) #> x <- 1 #> y <<- 2 lint( text = code_lines, linters = assignment_linter() ) # customizing using arguments code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter(allow_right_assign = TRUE) ) lint( text = \"x <<- 1\", linters = assignment_linter(allow_cascading_assign = FALSE) ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Replace <<- by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. writeLines(\"foo(bar = \\n 1)\") #> foo(bar = #> 1) lint( text = \"foo(bar = \\n 1)\", linters = assignment_linter(allow_trailing = FALSE) ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[assignment_linter] Assignment = should not be trailing at the end of a line. lint( text = \"x %<>% as.character()\", linters = assignment_linter(allow_pipe_assign = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Linter metadata from a package — available_linters","title":"Get Linter metadata from a package — available_linters","text":"available_linters() obtains tagged list Linters available package. available_tags() searches available tags.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Linter metadata from a package — available_linters","text":"","code":"available_linters(packages = \"lintr\", tags = NULL, exclude_tags = \"deprecated\") available_tags(packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Linter metadata from a package — available_linters","text":"packages character vector packages search linters. tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. exclude_tags Tags exclude results. Linters least one matching tag returned. 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\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] trimws (R 3.2.0) is not available for dependency R >= 3.0.0. lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] str2lang (R 3.6.0) is not available for dependency R >= 3.2.0. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). lint( text = \"sum(grepl(pattern, x)) == 0\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). # okay lint( text = \"!any(x == y)\", linters = boolean_arithmetic_linter() ) lint( text = \"!any(grepl(pattern, x))\", linters = boolean_arithmetic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Brace linter — brace_linter","title":"Brace linter — brace_linter","text":"Perform various style checks related placement spacing curly braces:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Brace linter — brace_linter","text":"","code":"brace_linter(allow_single_line = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Brace linter — brace_linter","text":"allow_single_line TRUE, allow open closed curly pair line.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Brace linter — brace_linter","text":"Opening curly braces never line always followed newline. Opening curly braces space . Closing curly braces line unless followed else. Closing curly braces conditions line corresponding else. Either neither branch /else use curly braces, .e., either branches use {...} neither . Functions spanning multiple lines use curly braces.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Brace linter — brace_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Brace linter — brace_linter","text":"","code":"# will produce lints lint( text = \"f <- function() { 1 }\", linters = brace_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line. #> ::warning file=,line=1,col=21::file=,line=1,col=21,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. writeLines(\"if (TRUE) {\\n return(1) }\") #> if (TRUE) { #> return(1) } lint( text = \"if (TRUE) {\\n return(1) }\", linters = brace_linter() ) #> ::warning file=,line=2,col=12::file=,line=2,col=12,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. # okay writeLines(\"f <- function() {\\n 1\\n}\") #> f <- function() { #> 1 #> } lint( text = \"f <- function() {\\n 1\\n}\", linters = brace_linter() ) writeLines(\"if (TRUE) { \\n return(1) \\n}\") #> if (TRUE) { #> return(1) #> } lint( text = \"if (TRUE) { \\n return(1) \\n}\", linters = brace_linter() ) # customizing using arguments writeLines(\"if (TRUE) { return(1) }\") #> if (TRUE) { return(1) } lint( text = \"if (TRUE) { return(1) }\", linters = brace_linter(allow_single_line = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Checkstyle Report for lint results — checkstyle_output","title":"Checkstyle Report for lint results — checkstyle_output","text":"Generate report linting results using Checkstyle XML format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Checkstyle Report for lint results — checkstyle_output","text":"","code":"checkstyle_output(lints, filename = \"lintr_results.xml\")"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Checkstyle Report for lint results — checkstyle_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block comparison of class with == — class_equals_linter","title":"Block comparison of class with == — class_equals_linter","text":"Usage like class(x) == \"character\" prone error since class R general vector. correct version S3 classes inherits(): inherits(x, \"character\"). Often, class k . equivalent, example .character() .data.frame().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block comparison of class with == — class_equals_linter","text":"","code":"class_equals_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block comparison of class with == — class_equals_linter","text":"Similar reasoning applies class(x) %% \"character\".","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block comparison of class with == — class_equals_linter","text":"best_practices, consistency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block comparison of class with == — class_equals_linter","text":"","code":"# will produce lints lint( text = 'is_lm <- class(x) == \"lm\"', linters = class_equals_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with ==. lint( text = 'if (\"lm\" %in% class(x)) is_lm <- TRUE', linters = class_equals_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with %in%. # 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() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[commas_linter] Remove spaces before a comma. lint( text = \"mean(x,trim = 0.2,na.rm = TRUE)\", linters = commas_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[commas_linter] Put a space after a comma. #> ::warning file=,line=1,col=19::file=,line=1,col=19,[commas_linter] Put a space after a comma. lint( text = \"x[ ,, drop=TRUE]\", linters = commas_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commas_linter] Remove spaces before a comma. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Put a space after a comma. lint( text = \"x[1,]\", linters = commas_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Put a space after a comma. # 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() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Remove commented code. lint( text = \"x <- f() # g()\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[commented_code_linter] Remove commented code. lint( text = \"x + y # + z[1, 2]\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[commented_code_linter] Remove commented code. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[comparison_negation_linter] Use x != y, not !(x == y). lint( text = \"!(x > 2)\", linters = comparison_negation_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[comparison_negation_linter] Use x <= y, not !(x > y). # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. lint( text = \"stop('test', call. = TRUE)\", linters = condition_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. lint( text = \"stop('test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(.) to display the call in an error message. lint( text = \"stop('this is a', 'test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(.) to display the call in an error message. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste to build stop strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). lint( text = 'warning(paste0(\"a string\", \" another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste0 to build warning strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). # okay lint( text = 'stop(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(paste(\"a string\", \"another\", sep = \"-\"))', linters = condition_message_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Configurable linters — configurable_linters","title":"Configurable linters — configurable_linters","text":"Generic linters support custom configuration needs.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Configurable linters — configurable_linters","text":"following linters tagged 'configurable': absolute_path_linter assignment_linter backport_linter brace_linter 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"expect_false(x || (y && z))\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] 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. lint( text = \"stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))\", linters = conjunct_test_linter(allow_named_stopifnot = FALSE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Write multiple conditions like stopifnot(A, B) instead of stopifnot(A && B). The latter will produce better error messages in the case of failure. lint( text = \"dplyr::filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=23::file=,line=1,col=23,[conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). lint( text = \"filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=16::file=,line=1,col=16,[conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to stopifnot(). lint( text = \"assert_that(x); assert_that(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to assert_that(). # okay lint( text = \"stopifnot(x, y)\", linters = consecutive_assertion_linter() ) lint( text = 'assert_that(x, msg = \"Bad x!\"); assert_that(y)', linters = consecutive_assertion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=1,col=25::file=,line=1,col=25,[consecutive_mutate_linter] Unify consecutive calls to mutate(). # 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) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 2 to at most 1. # 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() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[duplicate_argument_linter] Avoid duplicate arguments in function calls. lint( text = \"fun(arg = 1, arg = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[duplicate_argument_linter] Avoid duplicate arguments in function calls. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. writeLines(\"x = {\\n}\") #> x = { #> } lint( text = \"x = {\\n}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. # okay lint( text = \"x <- { 3 + 4 }\", linters = empty_assignment_linter() ) lint( text = \"x <- NULL\", linters = empty_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality check with NA linter — equals_na_linter","title":"Equality check with NA linter — equals_na_linter","text":"Check x == NA, x != NA x %% NA. usage almost surely incorrect -- checks missing values done .na().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality check with NA linter — equals_na_linter","text":"","code":"equals_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Equality check with NA linter — equals_na_linter","text":"common_mistakes, correctness, default, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality check with NA linter — equals_na_linter","text":"","code":"# will produce lints lint( text = \"x == NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of x == NA lint( text = \"x != NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of x != NA lint( text = \"x %in% NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y). lint( text = \"expect_true(x <= y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y). lint( text = \"expect_true(x == (y == 2))\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y). # okay lint( text = \"expect_gt(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_lte(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_identical(x, y == 2)\", linters = expect_comparison_linter() ) lint( text = \"expect_true(x < y | x > y^2)\", linters = expect_comparison_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter enforces usage testthat::expect_identical() default expectation comparisons testthat suite. expect_true(identical(x, y)) equivalent unadvised method test. , testthat::expect_equal() used expect_identical() inappropriate, .e., x y need numerically equivalent instead fully identical (case, provide tolerance= argument expect_equal() explicitly). also applies inconvenient check full equality (e.g., names can ignored, case ignore_attr = \"names\" supplied expect_equal() (, 2nd edition, check.attributes = FALSE).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"expect_identical_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter allows expect_equal() three circumstances: named argument set (e.g. ignore_attr tolerance) Comparison made explicit decimal, e.g. expect_equal(x, 1.0) (implicitly setting tolerance) ... passed (wrapper functions might set arguments ignore_attr tolerance)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. lint( text = \"expect_true(identical(x, y))\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. # okay lint( text = \"expect_identical(x, y)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, check.attributes = FALSE)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, tolerance = 1e-6)\", linters = expect_identical_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"testthat::expect_length() exists specifically testing length() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"expect_length_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n) # okay lint( text = \"expect_length(x, 2L)\", linters = expect_length_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint expectation — expect_lint","title":"Lint expectation — expect_lint","text":"expectation 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n) # okay lint( text = 'expect_named(x, \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(colnames(x), \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(dimnames(x), \"a\")', linters = expect_named_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"testthat::expect_false() exists specifically testing output FALSE. testthat::expect_true() can also used tests negating output, better use tailored function instead. reverse also true -- use expect_false() instead expect_true(!).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"expect_not_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa. # okay lint( text = \"expect_false(x)\", linters = expect_not_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_null for checking NULL — expect_null_linter","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"Require usage expect_null(x) expect_equal(x, NULL) similar usages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"expect_null_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"testthat::expect_null() exists specifically testing NULL objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_equal(x, NULL) lint( text = \"expect_identical(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_identical(x, NULL) lint( text = \"expect_true(is.null(x))\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_true(is.null(x)) # okay lint( text = \"expect_null(x)\", linters = expect_null_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s3_class() — expect_s3_class_linter","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"testthat::expect_s3_class() exists specifically testing class S3 objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"expect_s3_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. lint( text = 'expect_equal(class(x), \"numeric\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. # okay lint( text = 'expect_s3_class(x, \"data.frame\")', linters = expect_s3_class_linter() ) lint( text = 'expect_type(x, \"double\")', linters = expect_s3_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"testthat::expect_s4_class() exists specifically testing class S4 objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"expect_s4_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s4_class_linter] expect_s4_class(x, k) is better than expect_true(is(x, k)). Note also expect_s3_class() available for testing S3 objects. # okay lint( text = 'expect_s4_class(x, \"Matrix\")', linters = expect_s4_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"testthat::expect_true() testthat::expect_false() exist specifically testing TRUE/FALSE value object. testthat::expect_equal() testthat::expect_identical() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"expect_true_false_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE) lint( text = \"expect_equal(x, FALSE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE) # okay lint( text = \"expect_true(x)\", linters = expect_true_false_linter() ) lint( text = \"expect_false(x)\", linters = expect_true_false_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"testthat::expect_type() exists specifically testing storage type objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"expect_type_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t) lint( text = 'expect_identical(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t) # okay lint( text = 'expect_type(x, \"double\")', linters = expect_type_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[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. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter(allow_unescaped = TRUE) ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. code_lines <- 'stringr::str_subset(x, \"\\\\\\\\$\")' writeLines(code_lines) #> stringr::str_subset(x, \"\\\\$\") lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[fixed_regex_linter] 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. lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. # 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() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. lint( text = \"for (x in foo(x, y)) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. # okay lint( text = \"for (xi in x) { TRUE }\", linters = for_loop_index_linter() ) lint( text = \"for (col in DF$col) { TRUE }\", linters = for_loop_index_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function argument linter — function_argument_linter","title":"Function argument linter — function_argument_linter","text":"Check arguments defaults come last function declarations, per tidyverse design guide. Changing argument order can breaking change. alternative changing argument order instead set default arguments NULL.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function argument linter — function_argument_linter","text":"","code":"function_argument_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function argument linter — function_argument_linter","text":"best_practices, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function argument linter — function_argument_linter","text":"","code":"# will produce lints lint( text = \"function(y = 1, z = 2, x) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[function_argument_linter] Arguments without defaults should come before arguments with defaults. lint( text = \"function(x, y, z = 1, ..., w) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=28::file=,line=1,col=28,[function_argument_linter] Arguments without defaults should come before arguments with defaults. # okay lint( text = \"function(x, y = 1, z = 2) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, w, z = 1, ...) {}\", linters = function_argument_linter() ) lint( text = \"function(y = 1, z = 2, x = NULL) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, z = 1, ..., w = NULL) {}\", linters = function_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function left parentheses linter — function_left_parentheses_linter","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Check left parentheses function call spaces (e.g. mean (1:3)). Although syntactically valid, makes code difficult read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"function_left_parentheses_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Exceptions made control flow functions (, , etc.).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function left parentheses linter — function_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"mean (x)\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. lint( text = \"stats::sd(c (x, y, z))\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. # okay lint( text = \"mean(x)\", linters = function_left_parentheses_linter() ) lint( text = \"stats::sd(c(x, y, z))\", linters = function_left_parentheses_linter() ) lint( text = \"foo <- function(x) (x + 1)\", linters = function_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"return(x <- ...) either distracting (x ignored), confusing (assigning x side effect muddled dual-purpose expression).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"function_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"# will produce lints lint( text = \"foo <- function(x) return(y <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. lint( text = \"foo <- function(x) return(x <<- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. writeLines(\"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\") #> e <- new.env() #> foo <- function(x) return(e$val <- x + 1) lint( text = \"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=2,col=27::file=,line=2,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. # okay lint( text = \"foo <- function(x) return(x + 1)\", linters = function_return_linter() ) code_lines <- \" foo <- function(x) { x <<- x + 1 return(x) } \" lint( text = code_lines, linters = function_return_linter() ) code_lines <- \" e <- new.env() foo <- function(x) { e$val <- x + 1 return(e$val) } \" writeLines(code_lines) #> #> e <- new.env() #> foo <- function(x) { #> e$val <- x + 1 #> return(e$val) #> } #> lint( text = code_lines, linters = function_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract text from STR_CONST nodes — get_r_string","title":"Extract text from STR_CONST nodes — get_r_string","text":"Convert STR_CONST text() values R strings. useful account arbitrary character literals, 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/RtmpULBwEU/file16ca65cad61a\" #> #> $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/RtmpULBwEU/file16ca65cad61a\" #> #> $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/RtmpULBwEU/file16ca65cad61a\" #> #> $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() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[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. lint( text = \"if (!A) x else if (!B) y else z\", linters = if_not_else_linter() ) #> ::warning file=,line=1,col=20::file=,line=1,col=20,[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. lint( text = \"ifelse(!is_treatment, x, y)\", linters = if_not_else_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[if_not_else_linter] Prefer `ifelse(A, x, y)` to the less-readable `ifelse(!A, y, x)`. lint( text = \"if (!is.null(x)) x else 2\", linters = if_not_else_linter(exceptions = character()) ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[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. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. 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) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[if_switch_linter] Prefer repeated if/else statements over overly-complicated switch() statements. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmin(x, y) is preferable to ifelse(x < y, x, y). lint( text = \"ifelse(x > 0, x, 0)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmax(x, y) is preferable to ifelse(x > y, x, y). # okay lint( text = \"pmin(5:1, pi)\", linters = ifelse_censor_linter() ) lint( text = \"pmax(x, 0)\", linters = ifelse_censor_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Avoid implicit assignment in function calls — implicit_assignment_linter","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"Assigning inside function calls makes code difficult read, avoided, except functions capture side-effects (e.g. capture.output()).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"implicit_assignment_linter( except = c(\"bquote\", \"expression\", \"expr\", \"quo\", \"quos\", \"quote\"), 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() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. lint( text = \"mean(x <- 1:4)\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. # 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() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers. lint( text = \"x[2]\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=4::file=,line=1,col=4,[implicit_integer_linter] Use 2L or 2.0 to avoid implicit integers. lint( text = \"1:10\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[implicit_integer_linter] Use 10L or 10.0 to avoid implicit integers. # okay lint( text = \"x <- 1.0\", linters = implicit_integer_linter() ) lint( text = \"x <- 1L\", linters = implicit_integer_linter() ) lint( text = \"x[2L]\", linters = implicit_integer_linter() ) lint( text = \"1:10\", linters = implicit_integer_linter(allow_colon = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that indentation is consistent — indentation_linter","title":"Check that indentation is consistent — indentation_linter","text":"Check indentation consistent","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that indentation is consistent — indentation_linter","text":"","code":"indentation_linter( indent = 2L, hanging_indent_style = c(\"tidy\", \"always\", \"never\"), assignment_as_infix = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that indentation is consistent — indentation_linter","text":"indent Number spaces, code block indented relative parent code block. Used multi-line code blocks ({ ... }), function calls (( ... )) extractions ([ ... ], [[ ... ]]). Defaults 2. hanging_indent_style Indentation style multi-line function calls arguments first line. Defaults tidyverse style, .e. block indent used function call terminates ) separate line hanging indent . Note function multi-line function calls without arguments first line always expected block-indented arguments. hanging_indent_style \"tidy\", multi-line function definitions expected double-indented first line function definition contains arguments closing parenthesis line. assignment_as_infix Treat <- regular (.e. left-associative) infix operator? means, infix operators right hand side assignment trigger second level indentation:","code":"# complies to any style map( x, f, additional_arg = 42 ) # complies to \"tidy\" and \"never\" map(x, f, additional_arg = 42 ) # complies to \"always\" map(x, f, additional_arg = 42 ) # complies to \"tidy\" and \"always\" map(x, f, additional_arg = 42) # complies to \"never\" map(x, f, additional_arg = 42) # complies to \"tidy\" function( a, b) { # body } # complies to any style variable <- a %+% b %+% c # complies to assignment_as_infix = TRUE variable <- a %+% b %+% c # complies to assignment_as_infix = FALSE variable <- a %+% b %+% c"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check that indentation is consistent — indentation_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check that indentation is consistent — indentation_linter","text":"","code":"# will produce lints code_lines <- \"if (TRUE) {\\n1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=0::file=,line=2,col=0,[indentation_linter] Indentation should be 2 spaces but is 0 spaces. code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"always\") ) #> ::warning file=,line=2,col=2::file=,line=2,col=2,[indentation_linter] Hanging indent should be 4 spaces but is 2 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"never\") ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. # okay code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter() ) code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter(indent = 4) )"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Infix spaces linter — infix_spaces_linter","title":"Infix spaces linter — infix_spaces_linter","text":"Check infix operators surrounded spaces. Enforces corresponding Tidyverse style guide rule; see https://style.tidyverse.org/syntax.html#infix-operators.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"infix_spaces_linter(exclude_operators = NULL, allow_multiple_spaces = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Infix spaces linter — infix_spaces_linter","text":"exclude_operators Character vector operators exclude consideration linting. Default include following \"low-precedence\" operators: +, -, ~, >, >=, <, <=, ==, !=, &, &&, |, ||, <-, :=, <<-, ->, ->>, =, /, *, infix operator (exclude infixes passing \"%%\"). Note \"=\" 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() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators. lint( text = \"1:4 %>%sum()\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[infix_spaces_linter] Put spaces around all infix operators. # okay lint( text = \"x <- 1L\", linters = infix_spaces_linter() ) lint( text = \"1:4 %>% sum()\", linters = infix_spaces_linter() ) code_lines <- \" ab <- 1L abcdef <- 2L \" writeLines(code_lines) #> #> ab <- 1L #> abcdef <- 2L #> lint( text = code_lines, linters = infix_spaces_linter(allow_multiple_spaces = TRUE) ) lint( text = \"a||b\", linters = infix_spaces_linter(exclude_operators = \"||\") ) 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[inner_combine_linter] Combine inputs to vectorized functions first to take full advantage of vectorization, e.g., log10(c(x, y)) only runs the more expensive log10() once as compared to c(log10(x), log10(y)). # okay lint( text = \"log10(c(x, y, z))\", linters = inner_combine_linter() ) lint( text = \"c(log(x, base = 10), log10(x, base = 2))\", linters = inner_combine_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":null,"dir":"Reference","previous_headings":"","what":"Is this an expression- or a file-level source object? — is_lint_level","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"Helper determining whether current source_expression contains expressions current file, just single expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"is_lint_level(source_expression, level = c(\"expression\", \"file\"))"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"source_expression parsed expression object, .e., element object returned get_source_expressions(). level level expression tested? \"expression\" means individual expression, \"file\" means expressions current file available.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"tmp <- 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = 'class(z) %in% c(\"numeric\", \"integer\")', linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] 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. # 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() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[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). lint( text = \"data.frame(`a` = 1)\", linters = keyword_quote_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[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). lint( text = 'my_list$\"key\"', linters = keyword_quote_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[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. lint( text = 's4obj@\"key\"', linters = keyword_quote_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[length_levels_linter] nlevels(x) is better than 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[length_test_linter] Checking the length of a logical vector is likely a mistake. Did you mean `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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"vapply(x, length, integer(1L))\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"purrr::map_int(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. # okay lint( text = \"lengths(x)\", linters = lengths_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=3,col=1::file=,line=3,col=1,[library_call_linter] Move all library calls to the top of the script. lint( text = \"library('dplyr', character.only = TRUE)\", linters = library_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[library_call_linter] Use symbols in library calls to avoid the need for 'character.only'. 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() ) #> ::warning file=,line=2,col=1::file=,line=2,col=1,[library_call_linter] Call library() directly, not vectorized with sapply(). code <- \"suppressMessages(library(dplyr))\\nsuppressMessages(library(tidyr))\" writeLines(code) #> suppressMessages(library(dplyr)) #> suppressMessages(library(tidyr)) lint( text = code, linters = library_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[library_call_linter] Unify consecutive calls to suppressMessages(). You can do so by writing all of the calls in one braced expression like suppressMessages({...}). # 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) ) #> ::warning file=,line=1,col=21::file=,line=1,col=21,[line_length_linter] Lines should not be more than 20 characters. This line is 23 characters. # okay lint( text = strrep(\"x\", 21L), linters = line_length_linter(length = 40L) )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a lint object — lint-s3","title":"Create a lint object — lint-s3","text":"Create lint object","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a lint object — lint-s3","text":"","code":"Lint( filename, line_number = 1L, column_number = 1L, type = c(\"style\", \"warning\", \"error\"), message = \"\", line = \"\", ranges = NULL, linter = \"\" )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a lint object — lint-s3","text":"filename path source file linted. line_number line number lint occurred. column_number column number lint occurred. type type lint. message message used describe lint error line code source lint occurred ranges list ranges line emphasized. linter deprecated. longer used.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a lint object — lint-s3","text":"object class c(\"lint\", \"list\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint a file, directory, or package — lint","title":"Lint a file, directory, or package — lint","text":"lint() lints single file. lint_dir() lints files directory. lint_package() lints likely locations R files package, .e. R/, tests/, inst/, vignettes/, data-raw/, demo/, exec/.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint a file, directory, or package — lint","text":"","code":"lint( filename, linters = NULL, ..., cache = FALSE, parse_settings = TRUE, text = NULL ) lint_dir( path = \".\", ..., relative_path = TRUE, exclusions = list(\"renv\", \"packrat\"), pattern = \"(?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 #> ::warning file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2::file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2::file=/tmp/RtmpULBwEU/file16cac2d22e3,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators. lint(\"a = 123\\n\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. lint(text = \"a = 123\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use 1L instead of int(1), i.e., use literals directly where possible, instead of coercion. lint( text = \"as.character(NA)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use NA_character_ instead of as.character(NA), i.e., use literals directly where possible, instead of coercion. lint( text = \"rlang::lgl(1L)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use TRUE instead of rlang::lgl(1L), i.e., use literals directly where possible, instead of coercion. # okay lint( text = \"1L\", linters = literal_coercion_linter() ) lint( text = \"NA_character_\", linters = literal_coercion_linter() ) lint( text = \"TRUE\", linters = literal_coercion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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()) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[number_linter] This is a number. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[number_linter] This is a number."},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"colSums() rowSums() clearer performant alternatives apply(x, 2, sum) apply(x, 1, sum) respectively case 2D arrays, matrices","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"matrix_apply_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"# will produce lints lint( text = \"apply(x, 1, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(x) rather than apply(x, 1, sum) lint( text = \"apply(x, 2, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x)) or colSums(x) if x has 2 dimensions rather than apply(x, 2, sum) lint( text = \"apply(x, 2, sum, na.rm = TRUE)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x, na.rm = TRUE)) or colSums(x, na.rm = TRUE) if x has 2 dimensions rather than apply(x, 2, sum, na.rm = TRUE) lint( text = \"apply(x, 2:4, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x), dims = 3) or colSums(x) if x has 4 dimensions rather than apply(x, 2:4, sum)"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing argument linter — missing_argument_linter","title":"Missing argument linter — missing_argument_linter","text":"Check missing arguments function calls (e.g. stats::median(1:10, )).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing argument linter — missing_argument_linter","text":"","code":"missing_argument_linter( except = c(\"alist\", \"quote\", \"switch\"), allow_trailing = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Missing argument linter — missing_argument_linter","text":"except character vector function names exceptions. allow_trailing always allow trailing empty arguments?","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing argument linter — missing_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing argument linter — missing_argument_linter","text":"","code":"# will produce lints lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[missing_argument_linter] Missing argument 2 in function call. # okay lint( text = 'tibble(x = \"a\")', linters = missing_argument_linter() ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(except = \"tibble\") ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(allow_trailing = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing package linter — missing_package_linter","title":"Missing package linter — missing_package_linter","text":"Check missing packages library(), require(), loadNamespace(), requireNamespace() calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing package linter — missing_package_linter","text":"","code":"missing_package_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing package linter — missing_package_linter","text":"common_mistakes, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing package linter — missing_package_linter","text":"","code":"# will produce lints lint( text = \"library(xyzxyz)\", linters = missing_package_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[missing_package_linter] Package 'xyzxyz' is not installed. # okay lint( text = \"library(stats)\", linters = missing_package_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify lintr defaults — modify_defaults","title":"Modify lintr defaults — modify_defaults","text":"Modify list defaults name, allowing replacement, deletion addition new elements.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify lintr defaults — modify_defaults","text":"","code":"modify_defaults(defaults, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify lintr defaults — modify_defaults","text":"defaults named list elements modify. ... arguments elements change. unnamed, argument automatically named. named argument already exists defaults, replaced new element. exist, added. value NULL, element removed.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify lintr defaults — modify_defaults","text":"modified list elements, sorted name. achieve sort platform-independent way, two transformations applied names: (1) replace _ 0 (2) convert tolower().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Modify lintr defaults — modify_defaults","text":"","code":"# custom list of undesirable functions: # remove `sapply` (using `NULL`) # add `cat` (with an accompanying message), # add `print` (unnamed, i.e. with no accompanying message) # add `source` (as taken from `all_undesirable_functions`) my_undesirable_functions <- modify_defaults( defaults = default_undesirable_functions, sapply = NULL, \"cat\" = \"No cat allowed\", \"print\", all_undesirable_functions[[\"source\"]] ) # list names of functions specified as undesirable names(my_undesirable_functions) #> [1] \".libPaths\" \"attach\" \"browser\" \"cat\" #> [5] \"debug\" \"debugcall\" \"debugonce\" \"detach\" #> [9] \"library\" \"mapply\" \"options\" \"par\" #> [13] \"print\" \"require\" \"setwd\" \"sink\" #> [17] \"source\" \"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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[namespace_linter] Package 'xyzxyz' is not installed. lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[namespace_linter] 'ssd' is not exported from {stats}. # okay lint( text = \"stats::sd(c(1, 2, 3))\", linters = namespace_linter() ) lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter(check_exports = FALSE) ) lint( text = \"stats:::ssd(c(1, 2, 3))\", linters = namespace_linter(check_nonexports = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of nested ifelse() calls — nested_ifelse_linter","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Calling ifelse() nested calls problematic two main reasons: can hard read -- mapping code expected output code can messy task/require lot mental bandwidth, especially code nests inefficient -- ifelse() can evaluate arguments yes (see https://stackoverflow.com/q/16275149); issue exacerbated nested calls","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"nested_ifelse_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Users can instead rely readable alternative modeled SQL CASE statements. 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() ) #> ::warning file=,line=1,col=22::file=,line=1,col=22,[nested_ifelse_linter] Don't use nested ifelse() calls; instead, try (1) data.table::fcase; (2) dplyr::case_when; or (3) using a lookup table. # okay lint( text = 'dplyr::case_when(x == \"a\" ~ 1L, x == \"b\" ~ 2L, TRUE ~ 3L)', linters = nested_ifelse_linter() ) lint( text = 'data.table::fcase(x == \"a\", 1L, x == \"b\", 2L, default = 3L)', linters = nested_ifelse_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=2,col=14::file=,line=2,col=14,[nested_pipe_linter] Don't nest pipes inside other calls. lint( text = \"df1 %>% inner_join(df2 %>% select(a, b))\", linters = nested_pipe_linter(allow_inline = FALSE) ) #> ::warning file=,line=1,col=20::file=,line=1,col=20,[nested_pipe_linter] Don't nest pipes inside other calls. 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() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[nonportable_path_linter] Use file.path() to construct portable file paths. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"nrow(filter(x, is_treatment))\", linters = nrow_subset_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"x %>% filter(x, is_treatment) %>% nrow()\", linters = nrow_subset_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. # 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() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[numeric_leading_zero_linter] Include the leading zero for fractional numeric constants. lint( text = \"x <- -.1\", linters = numeric_leading_zero_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[numeric_leading_zero_linter] Include the leading zero for fractional numeric constants. # 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() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[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. lint( text = \"x[nchar(x) > 0]\", linters = nzchar_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[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. # 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) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_length_linter] Variable and function names should not be longer than 10 characters. # 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\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match CamelCase. lint( text = \"xYz <- 1L\", linters = object_name_linter(styles = c(\"UPPERCASE\", \"lowercase\")) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match UPPERCASE or lowercase. lint( text = \"MyVar <- 1L\", linters = object_name_linter(styles = \"dotted.case\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match dotted.case. lint( text = \"asd <- 1L\", linters = object_name_linter(regexes = c(my_style = \"F$\", \"f$\")) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match my_style or /f$/. # 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() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols. 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\") ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[object_overwrite_linter] 'lint' is an exported object from package 'lintr'. Avoid re-using such symbols. # 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() ) #> ::warning file=,line=1,col=21::file=,line=1,col=21,[object_usage_linter] local variable 'x' assigned but may not be used # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[one_call_pipe_linter] Avoid pipe %>% for expressions with only a single call. lint( text = \"DT %>% .[grp == 'a', sum(v)]\", linters = one_call_pipe_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[one_call_pipe_linter] Avoid pipe %>% for expressions with only a single call. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"any(!x)\", linters = outer_negation_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. # 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() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[package_hooks_linter] .onLoad() should take two arguments, with the first starting with 'lib' and the second starting with 'pkg'. lint( text = \".onAttach <- function(lib, pkg) { require(foo) }\", linters = package_hooks_linter() ) #> ::warning file=,line=1,col=35::file=,line=1,col=35,[package_hooks_linter] Don't alter the search() path in .onAttach() by calling require(). lint( text = \".onDetach <- function(pkg) { }\", linters = package_hooks_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[package_hooks_linter] .onDetach() should take one argument starting with 'lib'. # 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() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[paren_body_linter] Put a space between a right parenthesis and a body expression. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] paste0(...) is better than paste(..., sep = \"\"). lint( text = 'paste(c(\"a\", \"b\"), collapse = \", \")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] toString(.) is more expressive than paste(., collapse = \", \"). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists lint( text = 'paste0(c(\"a\", \"b\"), sep = \" \")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] sep= is not a formal argument to paste0(); did you mean to use paste(), or collapse=? lint( text = 'paste0(rep(\"*\", 10L), collapse = \"\")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] strrep(x, times) is better than paste0(rep(x, times), collapse = \"\"). #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used. lint( text = 'paste0(\"http://site.com/\", path)', linters = paste_linter(allow_file_path = \"never\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = 'paste0(x, collapse = \"\")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used. # 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() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`. #> ::warning file=,line=1,col=18::file=,line=1,col=18,[pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`. # 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() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>. lint( text = \"1:3 %>% mean() %>% as.character()\", linters = pipe_consistency_linter(\"|>\") ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator. #> ::warning file=,line=1,col=16::file=,line=1,col=16,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator. # 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() ) #> ::warning file=,line=2,col=9::file=,line=2,col=9,[pipe_continuation_linter] Put a space before `%>%` and a new line after it, unless the full pipeline fits on one line. code_lines <- \"1:3 |> mean() |>\\n as.character()\" writeLines(code_lines) #> 1:3 |> mean() |> #> as.character() lint( text = code_lines, linters = pipe_continuation_linter() ) #> ::warning file=,line=1,col=15::file=,line=1,col=15,[pipe_continuation_linter] Put a space before `|>` and a new line after it, unless the full pipeline fits on one line. # okay lint( text = \"1:3 %>% mean() %>% as.character()\", linters = pipe_continuation_linter() ) code_lines <- \"1:3 %>%\\n mean() %>%\\n as.character()\" writeLines(code_lines) #> 1:3 %>% #> mean() %>% #> as.character() lint( text = code_lines, linters = pipe_continuation_linter() ) lint( text = \"1:3 |> mean() |> as.character()\", linters = pipe_continuation_linter() ) code_lines <- \"1:3 |>\\n mean() |>\\n as.character()\" writeLines(code_lines) #> 1:3 |> #> mean() |> #> as.character() lint( text = code_lines, linters = pipe_continuation_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of return() in magrittr pipelines — pipe_return_linter","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"return() inside magrittr pipeline actually execute return() like expect: \\(x) { x %>% return(); FALSE } return FALSE! technically work \"expected\" final statement function body, usage misleading. Instead, assign pipe outcome variable return .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"","code":"pipe_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"best_practices, common_mistakes","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"","code":"# will produce lints lint( text = \"function(x) x %>% return()\", linters = pipe_return_linter() ) #> ::warning file=,line=1,col=19::file=,line=1,col=19,[pipe_return_linter] Avoid return() as the final step of a magrittr pipeline. Instead, assign the output of the pipeline to a well-named object and return that. # okay code <- \"function(x) {\\n y <- sum(x)\\n return(y)\\n}\" writeLines(code) #> function(x) { #> y <- sum(x) #> return(y) #> } lint( text = code, linters = pipe_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/pkg_testthat_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Testthat linters — pkg_testthat_linters","title":"Testthat linters — pkg_testthat_linters","text":"Linters encouraging best practices within testthat suites.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/pkg_testthat_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Testthat linters — pkg_testthat_linters","text":"following linters tagged 'pkg_testthat': 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 yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of print() for logging — print_linter","title":"Block usage of print() for logging — print_linter","text":"default print method character vectors appropriate interactively inspecting objects, logging messages. Thus checked-usage like print(paste('Data ', nrow(DF), 'rows.')) better served using cat(), e.g. cat(sprintf('Data %d rows.\\n', nrow(DF))) (noting using cat() entails supplying line returns, glue::glue() might preferable sprintf() constructing templated strings). Lastly, note message() differs slightly cat() prints stderr default, stdout, still good option consider logging purposes.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of print() for logging — print_linter","text":"","code":"print_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of print() for logging — print_linter","text":"best_practices, consistency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of print() for logging — print_linter","text":"","code":"# will produce lints lint( text = \"print('a')\", linters = print_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[print_linter] Use cat() instead of print() logging messages. Use message() in cases calling for a signalled condition. lint( text = \"print(paste(x, 'y'))\", linters = print_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[print_linter] Use cat() instead of print() logging messages. Use message() in cases calling for a signalled condition. # okay lint( text = \"print(x)\", linters = print_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Character string quote linter — quotes_linter","title":"Character string quote linter — quotes_linter","text":"Check desired quote delimiter used string constants.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Character string quote linter — quotes_linter","text":"","code":"quotes_linter(delimiter = c(\"\\\"\", \"'\"))"},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Character string quote linter — quotes_linter","text":"delimiter quote delimiter accept. Defaults tidyverse default \" (double-quoted strings).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Character string quote linter — quotes_linter","text":"configurable, consistency, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Character string quote linter — quotes_linter","text":"","code":"# will produce lints lint( text = \"c('a', 'b')\", linters = quotes_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[quotes_linter] Only use double-quotes. #> ::warning file=,line=1,col=8::file=,line=1,col=8,[quotes_linter] Only use double-quotes. # okay lint( text = 'c(\"a\", \"b\")', linters = quotes_linter() ) code_lines <- \"paste0(x, '\\\"this is fine\\\"')\" writeLines(code_lines) #> paste0(x, '\"this is fine\"') lint( text = code_lines, linters = quotes_linter() ) # okay lint( text = \"c('a', 'b')\", linters = quotes_linter(delimiter = \"'\") )"},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":null,"dir":"Reference","previous_headings":"","what":"Read lintr settings — read_settings","title":"Read lintr settings — read_settings","text":"Lintr searches settings given source file following order: options defined linter.setting. linter_file directory linter_file project directory linter_file user home directory default_settings()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Read lintr settings — read_settings","text":"","code":"read_settings(filename)"},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Read lintr settings — read_settings","text":"filename Source file linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Read lintr settings — read_settings","text":"default linter_file name .lintr can changed option lintr.linter_file environment variable R_LINTR_LINTER_FILE file DCF file, see base::read.dcf() details. example .lintr file: Experimentally, also support keeping config plain R file. default look file named .lintr.R (directories search .lintr). still deciding future config support lintr, user feedback welcome. advantage R maps closely configs actually stored, whereas DCF approach requires somewhat awkward formatting parseable R code within valid DCF key-value pairs. main disadvantage R file might flexible, users tempted write configs side effects causing hard--detect bugs like YAML work, require new dependencies harder parse programmatically visually. example .lintr.R file:","code":"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\" )"},{"path":"https://lintr.r-lib.org/dev/reference/readability_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Readability linters — readability_linters","title":"Readability linters — readability_linters","text":"Linters highlighting readability issues, missing whitespace.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/readability_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Readability linters — readability_linters","text":"following linters tagged 'readability': boolean_arithmetic_linter brace_linter commas_linter commented_code_linter comparison_negation_linter conjunct_test_linter consecutive_assertion_linter consecutive_mutate_linter cyclocomp_linter empty_assignment_linter expect_length_linter expect_named_linter expect_not_linter expect_true_false_linter fixed_regex_linter for_loop_index_linter function_left_parentheses_linter function_return_linter if_not_else_linter if_switch_linter implicit_assignment_linter indentation_linter infix_spaces_linter inner_combine_linter is_numeric_linter keyword_quote_linter length_levels_linter lengths_linter library_call_linter line_length_linter matrix_apply_linter nested_ifelse_linter nested_pipe_linter numeric_leading_zero_linter object_length_linter object_overwrite_linter object_usage_linter one_call_pipe_linter outer_negation_linter paren_body_linter pipe_call_linter pipe_consistency_linter pipe_continuation_linter quotes_linter redundant_equals_linter rep_len_linter repeat_linter sample_int_linter scalar_in_linter semicolon_linter sort_linter spaces_inside_linter spaces_left_parentheses_linter stopifnot_all_linter string_boundary_linter system_file_linter T_and_F_symbol_linter unnecessary_concatenation_linter unnecessary_lambda_linter unnecessary_nesting_linter unnecessary_placeholder_linter unreachable_code_linter which_grepl_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of ==, != on logical vectors — redundant_equals_linter","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"Testing x == TRUE redundant x logical vector. Wherever used improve readability, solution instead improve naming object better indicate contents logical. can done using prefixes (, , can, etc.). example, is_child, has_parent_supervision, can_watch_horror_movie clarify logical nature, child, parent_supervision, watch_horror_movie .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"","code":"redundant_equals_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"best_practices, common_mistakes, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"","code":"# will produce lints lint( text = \"if (any(x == TRUE)) 1\", linters = redundant_equals_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[redundant_equals_linter] Using == on a logical vector is redundant. Well-named logical vectors can be used directly in filtering. For data.table's `i` argument, wrap the column name in (), like `DT[(is_treatment)]`. lint( text = \"if (any(x != FALSE)) 0\", linters = redundant_equals_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[redundant_equals_linter] Using != on a logical vector is redundant. Well-named logical vectors can be used directly in filtering. For data.table's `i` argument, wrap the column name in (), like `DT[(is_treatment)]`. # okay lint( text = \"if (any(x)) 1\", linters = redundant_equals_linter() ) lint( text = \"if (!all(x)) 0\", linters = redundant_equals_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"Expressions like ifelse(x, TRUE, FALSE) ifelse(x, FALSE, TRUE) redundant; just x !x suffice R code logical vectors core data structure. ifelse(x, 1, 0) also .numeric(x), even needed rarely.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"","code":"redundant_ifelse_linter(allow10 = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"allow10 Logical, default FALSE. TRUE, usage like ifelse(x, 1, 0) allowed, .e., usage like ifelse(x, TRUE, FALSE) linted.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"best_practices, configurable, consistency, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"","code":"# will produce lints lint( text = \"ifelse(x >= 2.5, TRUE, FALSE)\", linters = redundant_ifelse_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[redundant_ifelse_linter] Just use the logical condition (or its negation) directly instead of calling ifelse(x, TRUE, FALSE) lint( text = \"ifelse(x < 2.5, 1L, 0L)\", linters = redundant_ifelse_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[redundant_ifelse_linter] Prefer as.integer(x) to ifelse(x, 1L, 0L) if really needed. # okay lint( text = \"x >= 2.5\", linters = redundant_ifelse_linter() ) # Note that this is just to show the strict equivalent of the example above; # converting to integer is often unnecessary and the logical vector itself # should suffice. lint( text = \"as.integer(x < 2.5)\", linters = redundant_ifelse_linter() ) lint( text = \"ifelse(x < 2.5, 1L, 0L)\", linters = redundant_ifelse_linter(allow10 = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/regex_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Regular expression linters — regex_linters","title":"Regular expression linters — regex_linters","text":"Linters examine usage regular expressions functions executing user code.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/regex_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Regular expression linters — regex_linters","text":"following linters tagged 'regex': fixed_regex_linter regex_subset_linter string_boundary_linter which_grepl_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"Using value = TRUE grep() returns subset input matches pattern, e.g. grep(\"[-m]\", letters, value = TRUE) return first 13 elements (m).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"","code":"regex_subset_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"letters[grep(\"[-m]\", letters)] letters[grepl(\"[-m]\", letters)] return thing, circuitously verbosely. stringr package also provides even readable alternative, namely str_subset(), preferred versions using str_detect() str_which().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"Note x[grep(pattern, x)] grep(pattern, x, value = TRUE) completely interchangeable x character (commonly, x factor), output latter character vector former remains factor. still may preferable refactor code, may faster match pattern levels(x) use subset instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"best_practices, efficiency, regex","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"","code":"# will produce lints lint( text = \"x[grep(pattern, x)]\", linters = regex_subset_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[regex_subset_linter] Prefer grep(pattern, x, ..., value = TRUE) over x[grep(pattern, x, ...)] and x[grepl(pattern, x, ...)]. lint( text = \"x[stringr::str_which(x, pattern)]\", linters = regex_subset_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[regex_subset_linter] Prefer stringr::str_subset(x, pattern) over x[str_detect(x, pattern)] and x[str_which(x, pattern)]. # okay lint( text = \"grep(pattern, x, value = TRUE)\", linters = regex_subset_linter() ) lint( text = \"stringr::str_subset(x, pattern)\", linters = regex_subset_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"rep(x, length.= n) calls rep_len(x, n) \"hood\". latter thus direct equally readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"","code":"rep_len_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"","code":"# will produce lints lint( text = \"rep(1:3, length.out = 10)\", linters = rep_len_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[rep_len_linter] Use rep_len(x, n) instead of rep(x, length.out = n). # okay lint( text = \"rep_len(1:3, 10)\", linters = rep_len_linter() ) lint( text = \"rep(1:3, each = 2L, length.out = 10L)\", linters = rep_len_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Repeat linter — repeat_linter","title":"Repeat linter — repeat_linter","text":"Check (TRUE) used infinite loops.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Repeat linter — repeat_linter","text":"","code":"repeat_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Repeat linter — repeat_linter","text":"readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Repeat linter — repeat_linter","text":"","code":"# will produce lints lint( text = \"while (TRUE) { }\", linters = repeat_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[repeat_linter] Use 'repeat' instead of 'while (TRUE)' for infinite loops. # okay lint( text = \"repeat { }\", linters = repeat_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Return linter — return_linter","title":"Return linter — return_linter","text":"linter checks functions' return() expressions.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return linter — return_linter","text":"","code":"return_linter( return_style = c(\"implicit\", \"explicit\"), allow_implicit_else = TRUE, return_functions = NULL, except = NULL, except_regex = NULL )"},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return linter — return_linter","text":"return_style Character string naming return style. \"implicit\", default, enforces Tidyverse guide recommendation leave terminal returns implicit. \"explicit\" style requires return() always explicitly supplied. allow_implicit_else Logical, default TRUE. FALSE, functions terminal clause must always else clause, making NULL alternative explicit necessary. Similarly, functions terminal switch() statements must explicit default case. return_functions Character vector functions accepted terminal calls return_style = \"explicit\". addition exit functions base always allowed: stop(), q(), quit(), invokeRestart(), tryInvokeRestart(), UseMethod(), NextMethod(), standardGeneric(), callNextMethod(), .C(), .Call(), .External(), .Fortran(). except, except_regex Character vector functions checked return_style = \"explicit\". addition namespace hook functions never checked: .onLoad(), .onUnload(), .onAttach(), .onDetach(), .Last.lib(), .First() .Last(). except matches function names exactly, except_regex exclusion pattern matching rex::re_matches().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Return linter — return_linter","text":"configurable, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return linter — return_linter","text":"","code":"# will produce lints code <- \"function(x) {\\n return(x + 1)\\n}\" writeLines(code) #> function(x) { #> return(x + 1) #> } lint( text = code, linters = return_linter() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[return_linter] Use implicit return behavior; explicit return() is not needed. code <- \"function(x) {\\n x + 1\\n}\" writeLines(code) #> function(x) { #> x + 1 #> } lint( text = code, linters = return_linter(return_style = \"explicit\") ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[return_linter] All functions must have an explicit return(). code <- \"function(x) {\\n if (x > 0) 2\\n}\" writeLines(code) #> function(x) { #> if (x > 0) 2 #> } lint( text = code, linters = return_linter(allow_implicit_else = FALSE) ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[return_linter] All functions with terminal if statements must have a corresponding terminal else clause. # okay code <- \"function(x) {\\n x + 1\\n}\" writeLines(code) #> function(x) { #> x + 1 #> } lint( text = code, linters = return_linter() ) code <- \"function(x) {\\n return(x + 1)\\n}\" writeLines(code) #> function(x) { #> return(x + 1) #> } lint( text = code, linters = return_linter(return_style = \"explicit\") ) code <- \"function(x) {\\n if (x > 0) 2 else NULL\\n}\" writeLines(code) #> function(x) { #> if (x > 0) 2 else NULL #> } lint( text = code, linters = return_linter(allow_implicit_else = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/robustness_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Robustness linters — robustness_linters","title":"Robustness linters — robustness_linters","text":"Linters highlighting code robustness issues, possibly wrong edge case behavior.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/robustness_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Robustness linters — robustness_linters","text":"following linters tagged 'robustness': absolute_path_linter backport_linter class_equals_linter equals_na_linter for_loop_index_linter missing_package_linter namespace_linter nonportable_path_linter object_overwrite_linter routine_registration_linter sample_int_linter seq_linter strings_as_factors_linter T_and_F_symbol_linter terminal_close_linter undesirable_function_linter undesirable_operator_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Identify unregistered native routines — routine_registration_linter","title":"Identify unregistered native routines — routine_registration_linter","text":"preferable register routines efficiency safety.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Identify unregistered native routines — routine_registration_linter","text":"","code":"routine_registration_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Identify unregistered native routines — routine_registration_linter","text":"best_practices, efficiency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Identify unregistered native routines — routine_registration_linter","text":"","code":"# will produce lints lint( text = '.Call(\"cpp_routine\", PACKAGE = \"mypkg\")', linters = routine_registration_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[routine_registration_linter] Register your native code routines with useDynLib and R_registerRoutines(). lint( text = '.Fortran(\"f_routine\", PACKAGE = \"mypkg\")', linters = routine_registration_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[routine_registration_linter] Register your native code routines with useDynLib and R_registerRoutines(). # okay lint( text = \".Call(cpp_routine)\", linters = routine_registration_linter() ) lint( text = \".Fortran(f_routine)\", linters = routine_registration_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"sample.int() preferable sample() case sampling numbers 1 n. sample calls sample.int() \"hood\".","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"","code":"sample_int_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"efficiency, readability, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"","code":"# will produce lints lint( text = \"sample(1:10, 2)\", linters = sample_int_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...). lint( text = \"sample(seq(4), 2)\", linters = sample_int_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(seq(n), m, ...). lint( text = \"sample(seq_len(8), 2)\", linters = sample_int_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(seq_len(n), m, ...). # okay lint( text = \"sample(seq(1, 5, by = 2), 2)\", linters = sample_int_linter() ) lint( text = \"sample(letters, 2)\", linters = sample_int_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sarif_output.html","id":null,"dir":"Reference","previous_headings":"","what":"SARIF Report for lint results — sarif_output","title":"SARIF Report for lint results — sarif_output","text":"Generate report linting results using SARIF format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sarif_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"SARIF Report for lint results — sarif_output","text":"","code":"sarif_output(lints, filename = \"lintr_results.sarif\")"},{"path":"https://lintr.r-lib.org/dev/reference/sarif_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"SARIF Report for lint results — sarif_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage like x %in% ","title":"Block usage like x %in% ","text":"vector %% set appropriate matching vector set, set size 1, == appropriate.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage like x %in% ","text":"","code":"scalar_in_linter(in_operators = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block usage like x %in% ","text":"in_operators Character vector additional infix operators behave like %% operator, e.g. {data.table}'s %chin% operator.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage like x %in% ","text":"scalar %% vector OK, alternative ((vector == scalar)) circuitous & potentially less clear.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage like x %in% ","text":"best_practices, configurable, consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage like x %in% ","text":"","code":"# will produce lints lint( text = \"x %in% 1L\", linters = scalar_in_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[scalar_in_linter] Use comparison operators (e.g. ==, !=, etc.) to match length-1 scalars instead of %in%. Note that comparison operators preserve NA where %in% does not. lint( text = \"x %chin% 'a'\", linters = scalar_in_linter(in_operators = \"%chin%\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[scalar_in_linter] Use comparison operators (e.g. ==, !=, etc.) to match length-1 scalars instead of %chin%. Note that comparison operators preserve NA where %chin% does not. # okay lint( text = \"x %in% 1:10\", linters = scalar_in_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Semicolon linter — semicolon_linter","title":"Semicolon linter — semicolon_linter","text":"Check semicolons terminate expressions.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Semicolon linter — semicolon_linter","text":"","code":"semicolon_linter(allow_compound = FALSE, allow_trailing = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Semicolon linter — semicolon_linter","text":"allow_compound Logical, default FALSE. TRUE, \"compound\" semicolons (e.g. x; y, .e., line code) allowed. allow_trailing Logical, default FALSE. TRUE, \"trailing\" semicolons (.e., terminate lines code) allowed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Semicolon linter — semicolon_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Semicolon linter — semicolon_linter","text":"","code":"# will produce lints lint( text = \"a <- 1;\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[semicolon_linter] Remove trailing semicolons. lint( text = \"a <- 1; b <- 1\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[semicolon_linter] Replace compound semicolons by a newline. lint( text = \"function() { a <- 1; b <- 1 }\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=20::file=,line=1,col=20,[semicolon_linter] Replace compound semicolons by a newline. # okay lint( text = \"a <- 1\", linters = semicolon_linter() ) lint( text = \"a <- 1;\", linters = semicolon_linter(allow_trailing = TRUE) ) code_lines <- \"a <- 1\\nb <- 1\" writeLines(code_lines) #> a <- 1 #> b <- 1 lint( text = code_lines, linters = semicolon_linter() ) lint( text = \"a <- 1; b <- 1\", linters = semicolon_linter(allow_compound = TRUE) ) code_lines <- \"function() { \\n a <- 1\\n b <- 1\\n}\" writeLines(code_lines) #> function() { #> a <- 1 #> b <- 1 #> } lint( text = code_lines, linters = semicolon_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Sequence linter — seq_linter","title":"Sequence linter — seq_linter","text":"linter checks 1:length(...), 1:nrow(...), 1:ncol(...), 1:NROW(...) 1:NCOL(...) expressions base-R, usage conjunction seq() (e.g., seq(length(...)), seq(nrow(...)), etc.).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sequence linter — seq_linter","text":"","code":"seq_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Sequence linter — seq_linter","text":"Additionally, checks 1:n() ({dplyr}) 1:.N ({data.table}). often cause bugs right-hand side zero. safer use base::seq_len() base::seq_along() instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Sequence linter — seq_linter","text":"best_practices, consistency, default, efficiency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Sequence linter — seq_linter","text":"","code":"# will produce lints lint( text = \"seq(length(x))\", linters = seq_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[seq_linter] Use seq_along(...) instead of seq(length(...)), which is likely to be wrong in the empty edge case. lint( text = \"1:nrow(x)\", linters = seq_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[seq_linter] Use seq_len(nrow(...)) instead of 1:nrow(...), which is likely to be wrong in the empty edge case. lint( text = \"dplyr::mutate(x, .id = 1:n())\", linters = seq_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[seq_linter] Use seq_len(n()) instead of 1:n(), which is likely to be wrong in the empty edge case. # okay lint( text = \"seq_along(x)\", linters = seq_linter() ) lint( text = \"seq_len(nrow(x))\", linters = seq_linter() ) lint( text = \"dplyr::mutate(x, .id = seq_len(n()))\", linters = seq_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check for common mistakes around sorting vectors — sort_linter","title":"Check for common mistakes around sorting vectors — sort_linter","text":"linter checks common mistakes using order() sort().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check for common mistakes around sorting vectors — sort_linter","text":"","code":"sort_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Check for common mistakes around sorting vectors — sort_linter","text":"First, requires usage sort() .[order(.)]. sort() dedicated option sort list vector. legible around twice fast .[order(.)], gap performance growing vector size. Second, requires usage .unsorted() equivalents using sort(). base function .unsorted() exists test sortedness vector. Prefer inefficient less-readable equivalents like x != sort(x). goes checking x == sort(x) -- use !.unsorted(x) instead. Moreover, use x == sort(x) can risky sort() drops missing elements default, meaning == might end trying compare vectors differing lengths.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check for common mistakes around sorting vectors — sort_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check for common mistakes around sorting vectors — sort_linter","text":"","code":"# will produce lints lint( text = \"x[order(x)]\", linters = sort_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[sort_linter] sort(x, na.last = TRUE) is better than x[order(x)]. Note that it's always preferable to save the output of order() for the same variable as a local variable than to re-compute it. lint( text = \"x[order(x, decreasing = TRUE)]\", linters = sort_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[sort_linter] sort(x, decreasing = TRUE, na.last = TRUE) is better than x[order(x, decreasing = TRUE)]. Note that it's always preferable to save the output of order() for the same variable as a local variable than to re-compute it. lint( text = \"sort(x) == x\", linters = sort_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sort_linter] Use !is.unsorted(x) to test the sortedness of a vector. # okay lint( text = \"x[sample(order(x))]\", linters = sort_linter() ) lint( text = \"y[order(x)]\", linters = sort_linter() ) lint( text = \"sort(x, decreasing = TRUE) == x\", linters = sort_linter() ) # If you are sorting several objects based on the order of one of them, such # as: x <- sample(1:26) y <- letters newx <- x[order(x)] newy <- y[order(x)] # This will be flagged by the linter. However, in this very specific case, # it would be clearer and more efficient to run order() once and assign it # to an object, rather than mix and match order() and sort() index <- order(x) newx <- x[index] newy <- y[index]"},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Spaces inside linter — spaces_inside_linter","title":"Spaces inside linter — spaces_inside_linter","text":"Check parentheses square brackets spaces directly inside , .e., directly following opening delimiter directly preceding closing delimiter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spaces inside linter — spaces_inside_linter","text":"","code":"spaces_inside_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Spaces inside linter — spaces_inside_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spaces inside linter — spaces_inside_linter","text":"","code":"# will produce lints lint( text = \"c( TRUE, FALSE )\", linters = spaces_inside_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[spaces_inside_linter] Do not place spaces after parentheses. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[spaces_inside_linter] Do not place spaces before parentheses. lint( text = \"x[ 1L ]\", linters = spaces_inside_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[spaces_inside_linter] Do not place spaces after square brackets. #> ::warning file=,line=1,col=6::file=,line=1,col=6,[spaces_inside_linter] Do not place spaces before square brackets. # okay lint( text = \"c(TRUE, FALSE)\", linters = spaces_inside_linter() ) lint( text = \"x[1L]\", linters = spaces_inside_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Spaces before parentheses linter — spaces_left_parentheses_linter","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"Check left parentheses space unless function call.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"","code":"spaces_left_parentheses_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"if(TRUE) x else y\", linters = spaces_left_parentheses_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call. # okay lint( text = \"if (TRUE) x else y\", linters = spaces_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require correct sprintf() calls — sprintf_linter","title":"Require correct sprintf() calls — sprintf_linter","text":"Check inconsistent number arguments arguments incompatible types (literal arguments) sprintf() calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require correct sprintf() calls — sprintf_linter","text":"","code":"sprintf_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require correct sprintf() calls — sprintf_linter","text":"gettextf() calls also included, since gettextf() thin wrapper around sprintf().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require correct sprintf() calls — sprintf_linter","text":"common_mistakes, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require correct sprintf() calls — sprintf_linter","text":"","code":"# will produce lints lint( text = 'sprintf(\"hello %s %s %d\", x, y)', linters = sprintf_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sprintf_linter] too few arguments # okay lint( text = 'sprintf(\"hello %s %s %d\", x, y, z)', linters = sprintf_linter() ) lint( text = 'sprintf(\"hello %s %s %d\", x, y, ...)', linters = sprintf_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of all() within stopifnot() — stopifnot_all_linter","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"stopifnot() actually checks () \"hood\" vector, produces better error message stopifnot(()) .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"","code":"stopifnot_all_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"","code":"# will produce lints lint( text = \"stopifnot(all(x > 0))\", linters = stopifnot_all_linter() ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[stopifnot_all_linter] Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under the hood' and provides a better error message in case of failure. lint( text = \"stopifnot(y > 3, all(x < 0))\", linters = stopifnot_all_linter() ) #> ::warning file=,line=1,col=18::file=,line=1,col=18,[stopifnot_all_linter] Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under the hood' and provides a better error message in case of failure. # okay lint( text = \"stopifnot(is.null(x) || all(x > 0))\", linters = stopifnot_all_linter() ) lint( text = \"assert_that(all(x > 0))\", linters = stopifnot_all_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"startsWith() used detect fixed initial substrings; readable efficient equivalents using grepl() substr(). c.f. startsWith(x, \"abc\"), grepl(\"^abc\", x), substr(x, 1L, 3L) == \"abc\".","code":""},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"","code":"string_boundary_linter(allow_grepl = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"allow_grepl Logical, default FALSE. TRUE, usages grepl() ignored. authors may prefer conciseness offered grepl() whereby NA input maps FALSE output, direct equivalent startsWith() endsWith().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"Ditto using endsWith() detect fixed terminal substrings. Note difference behavior grepl() startsWith() (endsWith()) handle missing values. particular, grepl(), NA inputs considered FALSE, startsWith(), NA inputs NA outputs. means strict equivalent grepl(\"^abc\", x) !.na(x) & startsWith(x, \"abc\"). lint grepl() usages default !.na() version explicit respect NA handling -- though documented, way grepl() handles missing inputs may surprising users.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"configurable, efficiency, readability, regex","code":""},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"","code":"# will produce lints lint( text = 'grepl(\"^a\", x)', linters = string_boundary_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[string_boundary_linter] Use !is.na(x) & startsWith(x, string) to detect a fixed initial substring, or, if missingness is not a concern, just startsWith(). Doing so is more readable and more efficient. lint( text = 'grepl(\"z$\", x)', linters = string_boundary_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[string_boundary_linter] Use !is.na(x) & endsWith(x, string) to detect a fixed terminal substring, or, if missingness is not a concern, just endsWith(). Doing so is more readable and more efficient. # okay lint( text = 'startsWith(x, \"a\")', linters = string_boundary_linter() ) lint( text = 'endsWith(x, \"z\")', linters = string_boundary_linter() ) # If missing values are present, the suggested alternative wouldn't be strictly # equivalent, so this linter can also be turned off in such cases. lint( text = 'grepl(\"z$\", x)', linters = string_boundary_linter(allow_grepl = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"Designed code bases written versions R 4.0 seeking upgrade R >= 4.0, one biggest pain points surely flipping default value stringsAsFactors TRUE FALSE.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"","code":"strings_as_factors_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"always possible tell statically whether change break existing code R dynamically typed -- e.g. data.frame(x) x string, code affected, x number, code unaffected. However, data.frame(x = \"\"), output unambiguously affected. can instead supply stringsAsFactors = TRUE, make code backwards-compatible. See https://developer.r-project.org/Blog/public/2020/02/16/stringsasfactors/.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"","code":"# will produce lints lint( text = 'data.frame(x = \"a\")', linters = strings_as_factors_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[strings_as_factors_linter] Supply an explicit value for stringsAsFactors for this code to work before and after R version 4.0. # okay lint( text = 'data.frame(x = \"a\", stringsAsFactors = TRUE)', linters = strings_as_factors_linter() ) lint( text = 'data.frame(x = \"a\", stringsAsFactors = FALSE)', linters = strings_as_factors_linter() ) lint( text = \"data.frame(x = 1.2)\", linters = strings_as_factors_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/style_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Style linters — style_linters","title":"Style linters — style_linters","text":"Linters highlighting code style issues.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/style_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Style linters — style_linters","text":"following linters tagged 'style': assignment_linter brace_linter commas_linter commented_code_linter condition_call_linter consecutive_assertion_linter cyclocomp_linter function_argument_linter function_left_parentheses_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter keyword_quote_linter library_call_linter line_length_linter numeric_leading_zero_linter object_length_linter object_name_linter object_usage_linter one_call_pipe_linter package_hooks_linter paren_body_linter pipe_call_linter pipe_consistency_linter pipe_continuation_linter quotes_linter repeat_linter return_linter semicolon_linter spaces_inside_linter spaces_left_parentheses_linter T_and_F_symbol_linter todo_comment_linter trailing_blank_lines_linter trailing_whitespace_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of file.path() with system.file() — system_file_linter","title":"Block usage of file.path() with system.file() — system_file_linter","text":"system.file() ... argument , internally, passed file.path(), including user code repetitive.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of file.path() with system.file() — system_file_linter","text":"","code":"system_file_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of file.path() with system.file() — system_file_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of file.path() with system.file() — system_file_linter","text":"","code":"# will produce lints lint( text = 'system.file(file.path(\"path\", \"to\", \"data\"), package = \"foo\")', linters = system_file_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[system_file_linter] Use the `...` argument of system.file() to expand paths, e.g. system.file(\"data\", \"model.csv\", package = \"myrf\") instead of system.file(file.path(\"data\", \"model.csv\"), package = \"myrf\") lint( text = 'file.path(system.file(package = \"foo\"), \"path\", \"to\", \"data\")', linters = system_file_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[system_file_linter] Use the `...` argument of system.file() to expand paths, e.g. system.file(\"data\", \"model.csv\", package = \"myrf\") instead of file.path(system.file(package = \"myrf\"), \"data\", \"model.csv\") # okay lint( text = 'system.file(\"path\", \"to\", \"data\", package = \"foo\")', linters = system_file_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Prohibit close() from terminating a function definition — terminal_close_linter","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"Functions end close(x) almost always better written using .exit(close(x)) close x defined /opened.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"","code":"terminal_close_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"best_practices, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"","code":"# will produce lints code <- paste( \"f <- function(fl) {\", \" conn <- file(fl, open = 'r')\", \" readLines(conn)\", \" close(conn)\", \"}\", sep = \"\\n\" ) writeLines(code) #> f <- function(fl) { #> conn <- file(fl, open = 'r') #> readLines(conn) #> close(conn) #> } lint( text = code, linters = terminal_close_linter() ) #> ::warning file=,line=4,col=3::file=,line=4,col=3,[terminal_close_linter] Use on.exit(close(x)) to close connections instead of running it as the last call in a function. # okay code <- paste( \"f <- function(fl) {\", \" conn <- file(fl, open = 'r')\", \" on.exit(close(conn))\", \" readLines(conn)\", \"}\", sep = \"\\n\" ) writeLines(code) #> f <- function(fl) { #> conn <- file(fl, open = 'r') #> on.exit(close(conn)) #> readLines(conn) #> } lint( text = code, linters = terminal_close_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/tidy_design_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidyverse design linters — tidy_design_linters","title":"Tidyverse design linters — tidy_design_linters","text":"Linters based guidelines described 'Tidy design principles' book.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/tidy_design_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Tidyverse design linters — tidy_design_linters","text":"following linters tagged 'tidy_design': condition_call_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"TODO comment linter — todo_comment_linter","title":"TODO comment linter — todo_comment_linter","text":"Check source contains TODO comments (case-insensitive).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"TODO comment linter — todo_comment_linter","text":"","code":"todo_comment_linter(todo = c(\"todo\", \"fixme\"), except_regex = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"TODO comment linter — todo_comment_linter","text":"todo Vector case-insensitive strings identify TODO comments. except_regex Vector case-sensitive regular expressions identify valid TODO comments.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"TODO comment linter — todo_comment_linter","text":"configurable, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"TODO comment linter — todo_comment_linter","text":"","code":"# will produce lints lint( text = \"x + y # TOODOO\", linters = todo_comment_linter(todo = \"toodoo\") ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[todo_comment_linter] Remove TODO comments. lint( text = \"pi <- 1.0 # FIIXMEE\", linters = todo_comment_linter(todo = \"fiixmee\") ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[todo_comment_linter] Remove TODO comments. lint( text = \"x <- TRUE # TOODOO(#1234): Fix this hack.\", linters = todo_comment_linter() ) # okay lint( text = \"x + y # my informative comment\", linters = todo_comment_linter() ) lint( text = \"pi <- 3.14\", linters = todo_comment_linter() ) lint( text = \"x <- TRUE\", linters = todo_comment_linter() ) lint( text = \"x <- TRUE # TODO(#1234): Fix this hack.\", linters = todo_comment_linter(except_regex = \"TODO\\\\(#[0-9]+\\\\):\") )"},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Trailing blank lines linter — trailing_blank_lines_linter","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"Check trailing blank lines source code.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"","code":"trailing_blank_lines_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"","code":"# will produce lints f <- tempfile() cat(\"x <- 1\\n\\n\", file = f) writeLines(readChar(f, file.size(f))) #> x <- 1 #> #> lint( filename = f, linters = trailing_blank_lines_linter() ) #> ::warning file=/tmp/RtmpULBwEU/file16ca5fec15a,line=2,col=1::file=/tmp/RtmpULBwEU/file16ca5fec15a,line=2,col=1,[trailing_blank_lines_linter] Remove trailing blank lines. unlink(f) # okay cat(\"x <- 1\\n\", file = f) writeLines(readChar(f, file.size(f))) #> x <- 1 #> lint( filename = f, linters = trailing_blank_lines_linter() ) unlink(f)"},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Trailing whitespace linter — trailing_whitespace_linter","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"Check space characters end source lines.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"","code":"trailing_whitespace_linter(allow_empty_lines = FALSE, allow_in_strings = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"allow_empty_lines Suppress lints lines contain whitespace. allow_in_strings Suppress lints trailing whitespace string constants.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"configurable, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"","code":"# will produce lints lint( text = \"x <- 1.2 \", linters = trailing_whitespace_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[trailing_whitespace_linter] Remove trailing whitespace. code_lines <- \"a <- TRUE\\n \\nb <- FALSE\" writeLines(code_lines) #> a <- TRUE #> #> b <- FALSE lint( text = code_lines, linters = trailing_whitespace_linter() ) #> ::warning file=,line=2,col=1::file=,line=2,col=1,[trailing_whitespace_linter] Remove trailing whitespace. # okay lint( text = \"x <- 1.2\", linters = trailing_whitespace_linter() ) lint( text = \"x <- 1.2 # comment about this assignment\", linters = trailing_whitespace_linter() ) code_lines <- \"a <- TRUE\\n \\nb <- FALSE\" writeLines(code_lines) #> a <- TRUE #> #> b <- FALSE lint( text = code_lines, linters = trailing_whitespace_linter(allow_empty_lines = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Undesirable function linter — undesirable_function_linter","title":"Undesirable function linter — undesirable_function_linter","text":"Report use undesirable functions suggest alternative.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Undesirable function linter — undesirable_function_linter","text":"","code":"undesirable_function_linter( fun = default_undesirable_functions, symbol_is_undesirable = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Undesirable function linter — undesirable_function_linter","text":"fun Named character vector. names(fun) correspond undesirable functions, values give description function undesirable. NA, additional information given lint message. Defaults default_undesirable_functions. make small customizations list, use modify_defaults(). symbol_is_undesirable Whether consider use undesirable function name symbol undesirable .","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Undesirable function linter — undesirable_function_linter","text":"best_practices, configurable, efficiency, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Undesirable function linter — undesirable_function_linter","text":"","code":"# defaults for which functions are considered undesirable names(default_undesirable_functions) #> [1] \".libPaths\" \"attach\" \"browser\" \"debug\" #> [5] \"debugcall\" \"debugonce\" \"detach\" \"library\" #> [9] \"mapply\" \"options\" \"par\" \"require\" #> [13] \"sapply\" \"setwd\" \"sink\" \"source\" #> [17] \"structure\" \"Sys.setenv\" \"Sys.setlocale\" \"trace\" #> [21] \"undebug\" \"untrace\" # will produce lints lint( text = \"sapply(x, mean)\", linters = undesirable_function_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"sapply\". As an alternative, use vapply() with an appropriate `FUN.VALUE=` argument to obtain type-stable simplification. lint( text = \"log10(x)\", linters = undesirable_function_linter(fun = c(\"log10\" = NA)) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"log10\". lint( text = \"log10(x)\", linters = undesirable_function_linter(fun = c(\"log10\" = \"use log()\")) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"log10\". As an alternative, use log(). lint( text = 'dir <- \"path/to/a/directory\"', linters = undesirable_function_linter(fun = c(\"dir\" = NA)) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"dir\". # okay lint( text = \"vapply(x, mean, FUN.VALUE = numeric(1))\", linters = undesirable_function_linter() ) lint( text = \"log(x, base = 10)\", linters = undesirable_function_linter(fun = c(\"log10\" = \"use log()\")) ) lint( text = 'dir <- \"path/to/a/directory\"', linters = undesirable_function_linter(fun = c(\"dir\" = NA), symbol_is_undesirable = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Undesirable operator linter — undesirable_operator_linter","title":"Undesirable operator linter — undesirable_operator_linter","text":"Report use undesirable operators, e.g. ::: <<- suggest alternative.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Undesirable operator linter — undesirable_operator_linter","text":"","code":"undesirable_operator_linter(op = default_undesirable_operators)"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Undesirable operator linter — undesirable_operator_linter","text":"op Named character vector. names(op) correspond undesirable operators, values give description operator undesirable. NA, additional information given lint message. Defaults default_undesirable_operators. make small customizations list, use modify_defaults().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Undesirable operator linter — undesirable_operator_linter","text":"best_practices, configurable, efficiency, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Undesirable operator linter — undesirable_operator_linter","text":"","code":"# defaults for which functions are considered undesirable names(default_undesirable_operators) #> [1] \"->>\" \":::\" \"<<-\" # will produce lints lint( text = \"a <<- log(10)\", linters = undesirable_operator_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[undesirable_operator_linter] Avoid undesirable operator `<<-`. It assigns outside the current environment in a way that can be hard to reason about. Prefer fully-encapsulated functions wherever possible, or, if necessary, assign to a specific environment with assign(). Recall that you can create an environment at the desired scope with new.env(). lint( text = \"mtcars$wt\", linters = undesirable_operator_linter(op = c(\"$\" = \"As an alternative, use the `[[` accessor.\")) ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[undesirable_operator_linter] Avoid undesirable operator `$`. As an alternative, use the `[[` accessor. # okay lint( text = \"a <- log(10)\", linters = undesirable_operator_linter() ) lint( text = 'mtcars[[\"wt\"]]', linters = undesirable_operator_linter(op = c(\"$\" = NA)) ) lint( text = 'mtcars[[\"wt\"]]', linters = undesirable_operator_linter(op = c(\"$\" = \"As an alternative, use the `[[` accessor.\")) )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Unneeded concatenation linter — unnecessary_concatenation_linter","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"Check c() function used without arguments single constant.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"","code":"unnecessary_concatenation_linter(allow_single_expression = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"allow_single_expression Logical, default TRUE. FALSE, one-expression usages c() always linted, e.g. c(x) c(matrix(...)). cases, c() used side-effect stripping non-name attributes; usually preferable use readable .vector() instead. .vector() always preferable, example environments (especially, R6 objects), case list() better alternative.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"configurable, efficiency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"","code":"# will produce lints lint( text = \"x <- c()\", linters = unnecessary_concatenation_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[unnecessary_concatenation_linter] Replace unnecessary c() by NULL or, whenever possible, vector() seeded with the correct type and/or length. lint( text = \"x <- c(TRUE)\", linters = unnecessary_concatenation_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[unnecessary_concatenation_linter] Remove unnecessary c() of a constant. lint( text = \"x <- c(1.5 + 2.5)\", linters = unnecessary_concatenation_linter(allow_single_expression = FALSE) ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[unnecessary_concatenation_linter] Remove unnecessary c() of a constant expression. Replace with as.vector() if c() is used to strip attributes, e.g. in converting an array to a vector. # okay lint( text = \"x <- NULL\", linters = unnecessary_concatenation_linter() ) # In case the intent here was to seed a vector of known size lint( text = \"x <- integer(4L)\", linters = unnecessary_concatenation_linter() ) lint( text = \"x <- TRUE\", linters = unnecessary_concatenation_linter() ) lint( text = \"x <- c(1.5 + 2.5)\", linters = unnecessary_concatenation_linter(allow_single_expression = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"Using anonymous function , e.g., lapply() always necessary, e.g. lapply(DF, sum) lapply(DF, function(x) sum(x)) former readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"","code":"unnecessary_lambda_linter(allow_comparison = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"allow_comparison Logical, default FALSE. TRUE, lambdas like function(x) foo(x) == 2, foo can extracted \"mapping\" function == vectorized instead called repeatedly, linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"Cases like lapply(x, \\(xi) grep(\"ptn\", xi)) excluded , though anonymous function can avoided, always readable.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"best_practices, configurable, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"","code":"# will produce lints lint( text = \"lapply(list(1:3, 2:4), function(xi) sum(xi))\", linters = unnecessary_lambda_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[unnecessary_lambda_linter] Pass sum directly as a symbol to lapply() instead of wrapping it in an unnecessary anonymous function. For example, prefer lapply(DF, sum) to lapply(DF, function(x) sum(x)). lint( text = \"sapply(x, function(xi) xi == 2)\", linters = unnecessary_lambda_linter() ) lint( text = \"sapply(x, function(xi) sum(xi) > 0)\", linters = unnecessary_lambda_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[unnecessary_lambda_linter] Compare to a constant after calling sapply() to get the full benefits of vectorization. Prefer sapply(x, foo) == 2 over sapply(x, function(xi) foo(xi) == 2, logical(1L)). # okay lint( text = \"lapply(list(1:3, 2:4), sum)\", linters = unnecessary_lambda_linter() ) lint( text = 'lapply(x, function(xi) grep(\"ptn\", xi))', linters = unnecessary_lambda_linter() ) lint( text = \"lapply(x, function(xi) data.frame(col = xi))\", linters = unnecessary_lambda_linter() ) lint( text = \"sapply(x, function(xi) xi == 2)\", linters = unnecessary_lambda_linter(allow_comparison = TRUE) ) lint( text = \"sapply(x, function(xi) sum(xi) > 0)\", linters = unnecessary_lambda_linter(allow_comparison = TRUE) ) lint( text = \"sapply(x, function(xi) sum(abs(xi)) > 10)\", linters = unnecessary_lambda_linter() ) lint( text = \"sapply(x, sum) > 0\", linters = unnecessary_lambda_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block instances of unnecessary nesting — unnecessary_nesting_linter","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"Excessive nesting harms readability. Use helper functions early returns reduce nesting wherever possible.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"","code":"unnecessary_nesting_linter( allow_assignment = TRUE, allow_functions = c(\"switch\", \"try\", \"tryCatch\", \"withCallingHandlers\", \"quote\", \"expression\", \"bquote\", \"substitute\", \"with_parameters_test_that\", \"reactive\", \"observe\", \"observeEvent\", \"renderCachedPlot\", \"renderDataTable\", \"renderImage\", \"renderPlot\", \"renderPrint\", \"renderTable\", \"renderText\", \"renderUI\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"allow_assignment Logical, default TRUE, case braced expressions consisting single assignment skipped. FALSE, braced expressions one child expression linted. TRUE case facilitates interaction implicit_assignment_linter() certain cases implicit assignment necessary, braced assignment used distinguish assignment. See examples. allow_functions Character vector functions always allow one-child braced expressions. testthat::test_that() always allowed testthat requires braced expression code argument. defaults similarly compute expressions way worth highlighting em-bracing , even one expression, switch() allowed use control flow analogous /else.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"best_practices, configurable, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"","code":"# will produce lints code <- \"if (A) {\\n stop('A is bad!')\\n} else {\\n do_good()\\n}\" writeLines(code) #> if (A) { #> stop('A is bad!') #> } else { #> do_good() #> } lint( text = code, linters = unnecessary_nesting_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unnecessary_nesting_linter] Reduce the nesting of this if/else statement by unnesting the portion without an exit clause (i.e., stop(), return(), abort(), quit(), q()). code <- \"tryCatch(\\n {\\n foo()\\n },\\n error = identity\\n)\" writeLines(code) #> tryCatch( #> { #> foo() #> }, #> error = identity #> ) lint( text = code, linters = unnecessary_nesting_linter() ) code <- \"expect_warning(\\n {\\n x <- foo()\\n },\\n 'warned'\\n)\" writeLines(code) #> expect_warning( #> { #> x <- foo() #> }, #> 'warned' #> ) lint( text = code, linters = unnecessary_nesting_linter(allow_assignment = FALSE) ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[unnecessary_nesting_linter] Reduce the nesting of this statement by removing the braces {}. writeLines(\"if (x) { \\n if (y) { \\n return(1L) \\n } \\n}\") #> if (x) { #> if (y) { #> return(1L) #> } #> } lint( text = \"if (x) { \\n if (y) { \\n return(1L) \\n } \\n}\", linters = unnecessary_nesting_linter() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[unnecessary_nesting_linter] Don't use nested `if` statements, where a single `if` with the combined conditional expression will do. For example, instead of `if (x) { if (y) { ... }}`, use `if (x && y) { ... }`. lint( text = \"my_quote({x})\", linters = unnecessary_nesting_linter() ) # okay code <- \"if (A) {\\n stop('A is bad because a.')\\n} else {\\n stop('!A is bad too.')\\n}\" writeLines(code) #> if (A) { #> stop('A is bad because a.') #> } else { #> stop('!A is bad too.') #> } lint( text = code, linters = unnecessary_nesting_linter() ) code <- \"capture.output({\\n foo()\\n})\" writeLines(code) #> capture.output({ #> foo() #> }) lint( text = code, linters = unnecessary_nesting_linter() ) code <- \"expect_warning(\\n {\\n x <- foo()\\n },\\n 'warned'\\n)\" writeLines(code) #> expect_warning( #> { #> x <- foo() #> }, #> 'warned' #> ) lint( text = code, linters = unnecessary_nesting_linter() ) writeLines(\"if (x && y) { \\n return(1L) \\n}\") #> if (x && y) { #> return(1L) #> } lint( text = \"if (x && y) { \\n return(1L) \\n}\", linters = unnecessary_nesting_linter() ) writeLines(\"if (x) { \\n y <- x + 1L\\n if (y) { \\n return(1L) \\n } \\n}\") #> if (x) { #> y <- x + 1L #> if (y) { #> return(1L) #> } #> } lint( text = \"if (x) { \\n y <- x + 1L\\n if (y) { \\n return(1L) \\n } \\n}\", linters = unnecessary_nesting_linter() ) lint( text = \"my_quote({x})\", linters = unnecessary_nesting_linter(allow_functions = \"my_quote\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"argument placeholder . magrittr pipelines unnecessary passed first positional argument; using can cause confusion impacts readability.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"","code":"unnecessary_placeholder_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"true forward (%>%), assignment (%<>%), tee (%T>%) operators.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"","code":"# will produce lints lint( text = \"x %>% sum(., na.rm = TRUE)\", linters = unnecessary_placeholder_linter() ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[unnecessary_placeholder_linter] Don't use the placeholder (`.`) when it's not needed, i.e., when it's only used as the first positional argument in a pipeline step. # okay lint( text = \"x %>% sum(na.rm = TRUE)\", linters = unnecessary_placeholder_linter() ) lint( text = \"x %>% lm(data = ., y ~ z)\", linters = unnecessary_placeholder_linter() ) lint( text = \"x %>% outer(., .)\", linters = unnecessary_placeholder_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block unreachable code and comments following return statements — unreachable_code_linter","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"Code e.g. return() stop() deterministically false conditional loops like (FALSE) reached; typically vestigial code left refactoring sandboxing code, fine exploration, ultimately checked . Comments meant posterity placed final return().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"","code":"unreachable_code_linter( allow_comment_regex = getOption(\"covr.exclude_end\", \"# nocov end\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"allow_comment_regex Character vector regular expressions identify comments exclude finding unreachable terminal comments. default, includes default \"skip region\" end marker {covr} (option \"covr.exclude_end\", \"# nocov end\" unset). end marker {lintr} (settings$exclude_end) always included. Note regexes include initial comment character #.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"best_practices, configurable, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"","code":"# will produce lints code_lines <- \"f <- function() {\\n return(1 + 1)\\n 2 + 2\\n}\" writeLines(code_lines) #> f <- function() { #> return(1 + 1) #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=3,col=3::file=,line=3,col=3,[unreachable_code_linter] Remove code and comments coming after return() or stop(). code_lines <- \"if (FALSE) {\\n 2 + 2\\n}\" writeLines(code_lines) #> if (FALSE) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unreachable_code_linter] Remove code inside a conditional loop with a deterministically false condition. code_lines <- \"while (FALSE) {\\n 2 + 2\\n}\" writeLines(code_lines) #> while (FALSE) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unreachable_code_linter] Remove code inside a conditional loop with a deterministically false condition. code_lines <- \"f <- function() {\\n return(1)\\n # end skip\\n}\" writeLines(code_lines) #> f <- function() { #> return(1) #> # end skip #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=3,col=3::file=,line=3,col=3,[unreachable_code_linter] Remove code and comments coming after return() or stop(). # okay code_lines <- \"f <- function() {\\n return(1 + 1)\\n}\" writeLines(code_lines) #> f <- function() { #> return(1 + 1) #> } lint( text = code_lines, linters = unreachable_code_linter() ) code_lines <- \"if (foo) {\\n 2 + 2\\n}\" writeLines(code_lines) #> if (foo) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) code_lines <- \"while (foo) {\\n 2 + 2\\n}\" writeLines(code_lines) #> while (foo) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) code_lines <- \"f <- function() {\\n return(1)\\n # end skip\\n}\" writeLines(code_lines) #> f <- function() { #> return(1) #> # end skip #> } lint( text = code_lines, linters = unreachable_code_linter(allow_comment_regex = \"# end skip\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that imported packages are actually used — unused_import_linter","title":"Check that imported packages are actually used — unused_import_linter","text":"Check imported packages actually used","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that imported packages are actually used — unused_import_linter","text":"","code":"unused_import_linter( allow_ns_usage = FALSE, except_packages = c(\"bit64\", \"data.table\", \"tidyverse\"), interpret_glue = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that imported packages are actually used — unused_import_linter","text":"allow_ns_usage Suppress lints packages used via namespace. FALSE default pkg::fun() require library(pkg). can use requireNamespace(\"pkg\") ensure package installed without attaching . except_packages Character vector packages ignored. usually attached side effects. interpret_glue TRUE, interpret glue::glue() calls avoid false positives caused local variables used glue expression.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check that imported packages are actually used — unused_import_linter","text":"best_practices, common_mistakes, configurable, executing","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check that imported packages are actually used — unused_import_linter","text":"","code":"# will produce lints code_lines <- \"library(dplyr)\\n1 + 1\" writeLines(code_lines) #> library(dplyr) #> 1 + 1 lint( text = code_lines, linters = unused_import_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unused_import_linter] Package 'dplyr' is attached but never used. code_lines <- \"library(dplyr)\\ndplyr::tibble(a = 1)\" writeLines(code_lines) #> library(dplyr) #> dplyr::tibble(a = 1) lint( text = code_lines, linters = unused_import_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unused_import_linter] Don't attach package 'dplyr', which is only used by namespace. Check that it is installed using loadNamespace() instead. # okay code_lines <- \"library(dplyr)\\ntibble(a = 1)\" writeLines(code_lines) #> library(dplyr) #> tibble(a = 1) lint( text = code_lines, linters = unused_import_linter() ) code_lines <- \"library(dplyr)\\ndplyr::tibble(a = 1)\" writeLines(code_lines) #> library(dplyr) #> dplyr::tibble(a = 1) lint( text = code_lines, linters = unused_import_linter(allow_ns_usage = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":null,"dir":"Reference","previous_headings":"","what":"Use lintr in your project — use_lintr","title":"Use lintr in your project — use_lintr","text":"Create minimal lintr config file starting point customization","code":""},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Use lintr in your project — use_lintr","text":"","code":"use_lintr(path = \".\", type = c(\"tidyverse\", \"full\"))"},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Use lintr in your project — use_lintr","text":"path Path project root, .lintr file created. .lintr file already exists, error thrown. type kind configuration create? tidyverse creates minimal lintr config, based default linters (linters_with_defaults()). suitable following tidyverse style guide. full creates lintr config using available linters via all_linters().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Use lintr in your project — use_lintr","text":"Path generated configuration, invisibly.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Use lintr in your project — use_lintr","text":"","code":"if (FALSE) { # use the default set of linters lintr::use_lintr() # or try all linters lintr::use_lintr(type = \"full\") # then lintr::lint_dir() }"},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"Usage & conditional statements error-prone inefficient. condition (condition) expr must always length 1, case && preferred. Ditto | vs. ||.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"","code":"vector_logic_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"linter covers inputs () () conditions testthat::expect_true() testthat::expect_false(). Note & | generics, possible && / || perfect substitutes & method dispatch incompatible way. Moreover, wary code may side effects, commonly assignments. Consider ((<- foo(x)) | (b <- bar(y))) { ... } vs. ((<- foo(x)) || (b <- bar(y))) { ... }. || exits early, TRUE, second condition never evaluated b assigned. usage allowed Tidyverse style guide, code can easily refactored pulling assignment outside condition, using || still preferable.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"best_practices, common_mistakes, default, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"","code":"# will produce lints lint( text = \"if (TRUE & FALSE) 1\", linters = vector_logic_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[vector_logic_linter] Use `&&` in conditional expressions. lint( text = \"if (TRUE && (TRUE | FALSE)) 4\", linters = vector_logic_linter() ) #> ::warning file=,line=1,col=19::file=,line=1,col=19,[vector_logic_linter] Use `||` in conditional expressions. lint( text = \"filter(x, A && B)\", linters = vector_logic_linter() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[vector_logic_linter] Use `&` in subsetting expressions. # okay lint( text = \"if (TRUE && FALSE) 1\", linters = vector_logic_linter() ) lint( text = \"if (TRUE && (TRUE || FALSE)) 4\", linters = vector_logic_linter() ) lint( text = \"filter(x, A & B)\", linters = vector_logic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of grep over which(grepl(.)) — which_grepl_linter","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"(grepl(pattern, x)) grep(pattern, x), harder read requires two passes vector.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"","code":"which_grepl_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"consistency, efficiency, readability, regex","code":""},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"","code":"# will produce lints lint( text = \"which(grepl('^a', x))\", linters = which_grepl_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[which_grepl_linter] grep(pattern, x) is better than which(grepl(pattern, x)). # okay lint( text = \"which(grepl('^a', x) | grepl('^b', x))\", linters = which_grepl_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Whitespace linter — whitespace_linter","title":"Whitespace linter — whitespace_linter","text":"Check correct character used indentation.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Whitespace linter — whitespace_linter","text":"","code":"whitespace_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Whitespace linter — whitespace_linter","text":"Currently, supports linting presence tabs. Much ink spilled topic, encourage check references information.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Whitespace linter — whitespace_linter","text":"https://www.jwz.org/doc/tabs-vs-spaces.html https://blog.codinghorror.com/death---space-infidels/","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Whitespace linter — whitespace_linter","text":"consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Whitespace linter — whitespace_linter","text":"","code":"# will produce lints lint( text = \"\\tx\", linters = whitespace_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[whitespace_linter] Use spaces to indent, not tabs. # okay lint( text = \" x\", linters = whitespace_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"Convenience function converting nodes matched XPath-based linter logic Lint() object return.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"","code":"xml_nodes_to_lints( xml, source_expression, lint_message, type = c(\"style\", \"warning\", \"error\"), column_number_xpath = range_start_xpath, range_start_xpath = \"number(./@col1)\", range_end_xpath = \"number(./@col2)\" )"},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"xml xml_node object (generate one Lint) xml_nodeset object (generate several Lints), e.g. returned xml2::xml_find_all() xml2::xml_find_first() list xml_node objects. source_expression source expression object, e.g. returned typically lint(), generally get_source_expressions(). lint_message message included message Lint object. lint_message character vector length xml, -th lint given -th message. type type lint. column_number_xpath XPath expression return column number location lint. Defaults start range matched range_start_xpath. See details information. range_start_xpath XPath expression return range start location lint. Defaults start expression matched xml. See details information. range_end_xpath XPath expression return range end location lint. Defaults end expression matched xml. See details information.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"xml_nodes, lint. xml_nodesets, lints (list lints).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"location XPaths, column_number_xpath, range_start_xpath range_end_xpath evaluated using xml2::xml_find_num() usually form \"number(./relative/xpath)\". Note location line number changed lints spanning multiple lines ignore range_end_xpath. column_number_xpath range_start_xpath assumed always refer locations starting line xml node.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":null,"dir":"Reference","previous_headings":"","what":"Get the name of the function matched by an XPath — xp_call_name","title":"Get the name of the function matched by an XPath — xp_call_name","text":"Often, helpful tailor message lint record function matched lint logic. function encapsulates logic pull matched call common situations.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get the name of the function matched by an XPath — xp_call_name","text":"","code":"xp_call_name(expr, depth = 1L, condition = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get the name of the function matched by an XPath — xp_call_name","text":"expr xml_node xml_nodeset, e.g. xml2::xml_find_all(). depth Integer, default 1L. deep AST represented expr look find call? default, assume expr matched node corresponding node found directly. depth = 0L means expr matched directly SYMBOL_FUNCTION_CALL; depth > 1L means depth total nodes must traversed finding call. condition additional (XPath condition SYMBOL_FUNCTION_CALL required match. default (NULL) condition. See examples.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get the name of the function matched by an XPath — xp_call_name","text":"","code":"xml_from_code <- function(str) { xml2::read_xml(xmlparsedata::xml_parse_data(parse(text = str, keep.source = TRUE))) } xml <- xml_from_code(\"sum(1:10)\") xp_call_name(xml, depth = 2L) #> [1] \"sum\" xp_call_name(xml2::xml_find_first(xml, \"expr\")) #> [1] \"sum\" xml <- xml_from_code(c(\"sum(1:10)\", \"sd(1:10)\")) xp_call_name(xml, depth = 2L, condition = \"text() = 'sum'\") #> [1] \"sum\""},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block obvious ","title":"Block obvious ","text":"Yoda tests use (expected, actual) instead common (actual, expected). always possible detect statically; linter focuses simple case testing expression literal value, e.g. (1L, foo(x)) (foo(x), 1L).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block obvious ","text":"","code":"yoda_test_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block obvious ","text":"best_practices, package_development, pkg_testthat, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block obvious ","text":"","code":"# will produce lints lint( text = \"expect_equal(2, x)\", linters = yoda_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[yoda_test_linter] Compare objects in tests in the order 'actual', 'expected', not the reverse. For example, do expect_equal(foo(x), 2L) instead of expect_equal(2L, foo(x)). lint( text = 'expect_identical(\"a\", x)', linters = yoda_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[yoda_test_linter] Compare objects in tests in the order 'actual', 'expected', not the reverse. For example, do expect_identical(foo(x), 2L) instead of expect_identical(2L, foo(x)). # okay lint( text = \"expect_equal(x, 2)\", linters = yoda_test_linter() ) lint( text = 'expect_identical(x, \"a\")', linters = yoda_test_linter() )"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecations--breaking-changes-development-version","dir":"Changelog","previous_headings":"","what":"Deprecations & breaking changes","title":"lintr (development version)","text":"source_file= argument ids_with_token() with_id(). Passing linters name non-\"linter\"-classed functions. linter= argument Lint(). Linters closed_curly_linter(), open_curly_linter(), paren_brace_linter(), semicolon_terminator_linter().. with_defaults(). Linters closed_curly_linter(), open_curly_linter(), paren_brace_linter(), semicolon_terminator_linter(). Helper with_defaults(). all_linters() signature all_linters(..., packages) rather all_linters(packages, ...) (#2332, @MichaelChirico). forces packages= supplied name break users rely supplying packages= positionally, found none searching GitHub. Adjusted various lint messages consistency readability (#1330, @MichaelChirico). general, favor lint messages phrased like “Action, reason” “” piece message front--center. may breaking change code tests specific phrasing lints. extraction_operator_linter() deprecated. Although switching $ [[ robustness benefits package code, can lead non-idiomatic code many contexts (e.g. R6 classes, Shiny applications, etc.) (#2409, @IndrajeetPatil). enable detection $ operator extraction partial matching, use options(warnPartialMatchDollar = TRUE). unnecessary_nested_if_linter() deprecated subsumed new/general unnecessary_nesting_linter(). Drop support posting GitHub comments inside GitHub comment bot, Travis, Wercker, Jenkins CI tools (spurred #2148, @MichaelChirico). rely GitHub Actions linting CI, don’t see active users relying alternatives. welcome encourage community contributions get support different CI system going . cyclocomp_linter() longer part default linters (#2555, @IndrajeetPatil) tidyverse style guide doesn’t contain guidelines meeting certain complexity requirements. Note users cyclocomp_linter() configs may now need install {cyclocomp} intentionally, particular CI/CD pipelines. scalar_in_linter now configurable allow %% like operators linted. data.table operator %chin% longer linted default; use in_operators = \"%chin%\" continue linting . (@F-Noelle)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-development-version","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr (development version)","text":"expect_identical_linter() also skips expect_equal() comparison negative non-integers like -1.034 (#2411, @Bisaloo). parity fix since positive reals always skipped “high-precision” comparisons typically done get tests within tolerance, expect_identical() great substitution. object_name_linter() longer errors user-supplied regexes= capture groups (#2188, @MichaelChirico). .lintr config validation correctly accepts regular expressions compile perl = TRUE (#2375, @MichaelChirico). always valid (since rex::re_matches(), powers lint exclusion logic, also uses setting), new -front validation v3.1.1 incorrectly used perl = FALSE. .lintr configs set option lintr.linter_file environment variable R_LINTR_LINTER_FILE can point subdirectories (#2512, @MichaelChirico). indentation_linter() returns ranges[1L]==1L offending line 0 spaces (#2550, @MichaelChirico). literal_coercion_linter() doesn’t surface warning NAs coercion code like .integer(\"\") (#2566, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-default-linters-development-version","dir":"Changelog","previous_headings":"","what":"Changes to default linters","title":"lintr (development version)","text":"New default linter return_linter() style guide rule terminal returns left implicit (#1100, #2343, #2354, #2356, @MEO265 @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-development-version","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr (development version)","text":"helpful errors invalid configs (#2253, @MichaelChirico). encourage packages attached library(symbol), library(\"symbol\", character.= TRUE) “vectorized” approaches looping package names (part #884, @MichaelChirico). discourage many consecutive calls suppressMessages() suppressPackageStartupMessages() (part #884, @MichaelChirico). return_style (\"implicit\" default) checks functions confirm specified return style \"implicit\" \"explicit\" (#2271 part #884, @MichaelChirico, @AshesITR @MEO265). allow_implicit_else (default TRUE) , FALSE, checks terminal statements paired corresponding else statement (part #884, @MichaelChirico). return_functions customize functions equivalent return() “exit” clauses, e.g. rlang::abort() can considered addition default functions like stop() q() base (#2271 part #884, @MichaelChirico @MEO265). except customize functions ignored entirely (.e., whether return specified style checked; #2271 part #884, @MichaelChirico @MEO265). Namespace hooks like .onAttach() .onLoad() always ignored. except_regex, purpose except=, filters functions pattern. motivated {RUnit}, test suites based unit test functions matched pattern, e.g. ^Test, explicit return may awkward (#2335, @MichaelChirico). unnecessary_lambda_linter extended encourage vectorized comparisons possible, e.g. sapply(x, sum) > 0 instead sapply(x, function(x) sum(x) > 0) (part #884, @MichaelChirico). Toggle behavior argument allow_comparison. backport_linter() slightly faster moving expensive computations outside linting function (#2339, #2348, @AshesITR @MichaelChirico). Linter() new argument linter_level (default NA). used lint() efficiently check expression levels idiom (!is_lint_level(...)) { return(list()) } (#2351, @AshesITR). string_boundary_linter() recognizes regular expression calls like grepl(\"^abc$\", x) can replaced using == instead (#1613, @MichaelChirico). unreachable_code_linter() argument allow_comment_regex customizing “terminal” comments exclude (#2327, @MichaelChirico). # nolint end comments always excluded, {covr} exclusions (e.g. # nocov end) default. format() print() methods lint lints classes get new option width control printing width lint messages (#1884, @MichaelChirico). default controlled new option lintr.format_width; unset, wrapping occurs (matching earlier behavior). implicit_assignment_linter() gets custom message case using ( induce printing like (x <- foo()); use explicit call print() clarity (#2257, @MichaelChirico). New function node caching big efficiency gains linters (e.g. overall lint_package() improvement 14-27% core linting improvement 30%; #2357, @AshesITR). linters written around function usage, XPath performance searching many functions poor. new xml_find_function_calls() entry get_source_expressions() output caches function call nodes instead. See vignette creating linters details use . todo_comment_linter() new argument except_regex setting valid TODO comments, e.g. forcing TODO comments linked GitHub issues like TODO(#154) (#2047, @MichaelChirico). vector_logic_linter() extended recognize incorrect usage scalar operators && || inside subsetting expressions like dplyr::filter(x, && B) (#2166, @MichaelChirico). any_is_na_linter() extended catch unusual usage NA %% x (#2113, @MichaelChirico). make_linter_from_xpath() errors front lint_message missing (instead delaying error linter used, #2541, @MichaelChirico). paste_linter() extended recommend using paste() instead paste0() simply aggregating character vector collapse=, .e., sep= irrelevant (#1108, @MichaelChirico). expect_no_lint() added new function cover typical use case expecting lint message, akin recent {testthat} functions like expect_no_warning() (#2580, @F-Noelle).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-development-version","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr (development version)","text":"condition_call_linter() ensuring consistent use call. warning() stop(). default call. = FALSE follows tidyverse guidance displaying call (#2226, @Bisaloo) sample_int_linter() encouraging sample.int(n, ...) equivalents like sample(1:n, ...) (part #884, @MichaelChirico). stopifnot_all_linter() discourages tests () like stopifnot((x > 0)); stopifnot() runs () , uses better error message (part #884, @MichaelChirico). comparison_negation_linter() discouraging negated comparisons direct negation preferable, e.g. !(x == y) x != y (part #884, @MichaelChirico). nzchar_linter() encouraging nzchar() test empty strings, e.g. nchar(x) > 0 can nzchar(x) (part #884, @MichaelChirico). terminal_close_linter() discouraging using close() end functions (part #884, @MichaelChirico). usages robust errors, close() run intended. Put close() .exit() hook, use {withr} manage connections proper cleanup. rep_len_linter() encouraging use rep_len() directly instead rep(x, length.= n) (part #884, @MichaelChirico). which_grepl_linter() discouraging (grepl(ptn, x)) favor directly using grep(ptn, x) (part #884, @MichaelChirico). list_comparison_linter() discouraging comparisons output lapply(), e.g. lapply(x, sum) > 10 (part #884, @MichaelChirico). print_linter() discouraging usage print() string literals like print(\"Reached \") print(paste(\"Found\", nrow(DF), \"rows.\")) (#1894, @MichaelChirico). unnecessary_nesting_linter() discouraging overly-nested code early return eliminated sub-expression (inside ‘{’) preferable (#2317, #2334 part #884, @MichaelChirico). consecutive_mutate_linter() encouraging consecutive calls dplyr::mutate() combined (part #884, @MichaelChirico). if_switch_linter() encouraging switch() repeated /else tests (#2322 part #884, @MichaelChirico). nested_pipe_linter() discouraging pipes within pipes, e.g. df1 %>% inner_join(df2 %>% select(, b)) (part #884, @MichaelChirico). nrow_subset_linter() discouraging usage like nrow(subset(x, conditions)) favor something like (x, sum(conditions)) doesn’t require full subset x (#2313, #2314 part #884, @MichaelChirico). pipe_return_linter() discouraging usage return() inside {magrittr} pipeline (part #884, @MichaelChirico). one_call_pipe_linter() discouraging one-step pipelines like x |> .character() (#2330 part #884, @MichaelChirico). object_overwrite_linter() discouraging re-use upstream package exports local variables (#2344, #2346 part #884, @MichaelChirico @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-positives-development-version","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false positives","title":"lintr (development version)","text":"object_name_linter() object_length_linter() ignore {rlang} name injection like x |> mutate(\"{new_name}\" := foo(col)) (#1926, @MichaelChirico). checking applied cases. {data.table} -place assignments like DT[, \"sPoNGeBob\" := \"friend\"] still eligible lints.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"notes-development-version","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr (development version)","text":"user-facing messages now prepared using cli package (#2418, @IndrajeetPatil). messages reviewed updated informative consistent. {lintr} now depends R version 4.0.0. already implicitly due recursive upstream dependencies requiring version; ’ve simply made dependency explicit -front (#2569, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-312","dir":"Changelog","previous_headings":"","what":"lintr 3.1.2","title":"lintr 3.1.2","text":"CRAN release: 2024-03-25","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-positives-3-1-2","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false positives","title":"lintr 3.1.2","text":"unreachable_code_linter() ignores reachable code inline functions like function(x) (x > 2) stop() else x (#2259, @MEO265). ignores extractions explicit returns like lapply(l, function(x) foo(x)$bar) (#2258, @MichaelChirico). ignores calls RHS operators like lapply(l, function(x) \"\" %% names(x)) (#2310, @MichaelChirico). vector_logic_linter() recognizes cases bitwise &/| used correctly (#1453, @MichaelChirico). expect_comparison_linter() ignores faulty usage like expect_true(x, y > z) (#2083, @MichaelChirico). Note y > z passed info= argument, likely mistake. consecutive_assertion_linter() ignores cases second assertion follows intervening assignment = (#2444, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-negatives-3-1-2","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false negatives","title":"lintr 3.1.2","text":"missing_argument_linter() catches missing arguments calls several, e.g. foo(,,) gives 3 lints instead 2 (#2399, @MichaelChirico). duplicate_argument_linter() longer misses cases duplicate arguments comment comes argument name = (#2402, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"notes-3-1-2","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr 3.1.2","text":"Fixed test assuming specific parser error message recently changed r-devel (#2527, @IndrajeetPatil). @MichaelChirico taken CRAN maintainer duties package. Many thanks @jimhester 10 years 15 releases wearing hat!!","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-311","dir":"Changelog","previous_headings":"","what":"lintr 3.1.1","title":"lintr 3.1.1","text":"CRAN release: 2023-11-07","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"breaking-changes-3-1-1","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"lintr 3.1.1","text":"infix_spaces_linter() distinguishes <-, :=, <<- ->, ->>, .e. infix_spaces_linter(exclude_operators = \"->\") longer exclude ->> (#2115, @MichaelChirico). change breaking users relying manually-supplied exclude_operators containing \"<-\" also exclude := <<-. fix manually supply \":=\" \"<<-\" well. don’t expect change affect many users, fix simple, new behavior much transparent, including breakage minor release. Removed find_line() find_column() entries get_source_expressions() expression-level objects. marked deprecated since version 3.0.0. users found GitHub. also validate config files -front make clearer invalid configs present (#2195, @MichaelChirico). warning “invalid” settings, .e., settings part ?default_settings. think likely affect users declaring settings R, since variable defined config ’s setting must removed make clearer variables settings vs. ancillary.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-1-1","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.1.1","text":"sprintf_linter() doesn’t error cases whitespace ... arguments significant, e.g. sprintf(\"%s\", () \"\" else y), won’t parse whitespace removed (#2131, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-default-linters-3-1-1","dir":"Changelog","previous_headings":"","what":"Changes to default linters","title":"lintr 3.1.1","text":"assignment_linter() lints {magrittr} assignment pipe %<>% (#2008, @MichaelChirico). can deactivated setting new argument allow_pipe_assign TRUE. assumes glue() glue::glue() interpret_glue=TRUE (#2032, @MichaelChirico). finds function usages, including infix usage, inside glue() calls avoid false positives “unused objects” (#2029 #2069, @MichaelChirico). object_name_linter() longer attempts lint strings function calls LHS assignments (#1466, @MichaelChirico). infix_spaces_linter() allows finer control linting = different scenarios using parse tags EQ_ASSIGN, EQ_SUB, EQ_FORMALS (#1977, @MichaelChirico). equals_na_linter() checks x %% NA, convoluted form .na(x) (#2088, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-3-1-1","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr 3.1.1","text":"New exclusion sentinel # nolint next signify next line skip linting (#1791, @MichaelChirico). usual rules apply excluding specific linters, e.g. # nolint next: assignment_linter.. exact string used match subsequent-line exclusion controlled exclude_next config entry R option \"lintr.exclude_next\". New xp_call_name() helper facilitate writing custom linters (#2023, @MichaelChirico). helper converts matched XPath R function corresponds. useful including “offending” function lint’s message. New make_linter_from_xpath() facilitate making simple linters directly single XPath (#2064, @MichaelChirico). especially helpful making --fly/exploratory linters, also extends case linter can fully defined static lint message single XPath. Toggle lint progress indicators argument show_progress lint_dir() lint_package() (#972, @MichaelChirico). default still show progress interactive() sessions. Progress also now shown “proper” progress bar (utils::txtProgressBar()), particular solves issue progress . spilling well past width screen large directories. lint(), lint_dir(), lint_package() fail gracefully user mis-spells argument name (#2134, @MichaelChirico). Quarto files (.qmd) included lint_dir() default (#2150, @dave-lovell).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr 3.1.1","text":"library_call_linter() can detect library/require calls top script (#2027, #2043, #2163, #2170, @nicholas-masel @MichaelChirico). keyword_quote_linter() finding unnecessary discouraged quoting symbols assignment, function arguments, extraction (part #884, @MichaelChirico). Quoting unnecessary target valid R name, e.g. c(\"\" = 1) can c(= 1). goes assignment (\"\" <- 1) extraction (x$\"\"). quoting necessary, linter encourages backticks (e.g. x$`b` instead x$\"b\"). length_levels_linter() using specific function nlevels() instead checking length(levels(x)) (part #884, @MichaelChirico). scalar_in_linter() discouraging %% right-hand side scalar, e.g. x %% 1 (part #884, @MichaelChirico). if_not_else_linter() encouraging statements structured () x else y instead (!) y else x (part #884, @MichaelChirico). repeat_linter() encouraging repeat infinite loops instead (TRUE) (#2106, @MEO265). length_test_linter() detects common mistake length(x == 0) meant length(x) == 0 (#1991, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"extensions-to-existing-linters-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"Extensions to existing linters","title":"lintr 3.1.1","text":"fixed_regex_linter() gains option allow_unescaped (default FALSE) toggle linting regexes requiring escapes character classes (#1689, @MichaelChirico). Thus fixed_regex_linter(allow_unescaped = TRUE) lint grepl(\"[$]\", x) grepl(\"\", x) since latter use regex special characters. line_length_linter() helpfully includes line length lint message (#2057, @MichaelChirico). conjunct_test_linter() also lints usage like dplyr::filter(x, & B) favor using dplyr::filter(x, , B) (part #884; #2110 #2078, @salim-b @MichaelChirico). Option allow_filter toggles applies. allow_filter = \"always\" drops lints entirely, \"not_dplyr\" lints calls explicitly qualified dplyr::filter(). default, \"never\", assumes unqualified calls filter() dplyr::filter(). sort_linter() checks code like x == sort(x) better served using function .unsorted() (part #884, @MichaelChirico). paste_linter() gains detection file paths better constructed file.path(), e.g. paste0(dir, \"/\", file) better file.path(dir, file) (part #884, #2082, @MichaelChirico). exactly gets linted can fine-tuned allow_file_path option (\"double_slash\" default, alternatives \"never\" \"always\"). \"always\", rules ignored. \"double_slash\", paths appearing construct URL consecutive forward slashes (/) skipped. \"never\", even URLs constructed file.path(). seq_linter() recommends rev() lint message lints like nrow(x):1 (#1542, @MichaelChirico). function_argument_linter() detects usage missing() linted argument (#1546, @MichaelChirico). simplest fix function_argument_linter() lints typically set argument NULL default, case ’s usually preferable update function logic checking missing() check .null() instead. commas_linter() gains option allow_trailing (default FALSE) allow trailing commas indexing. (#2104, @MEO265) checks code inside (FALSE) conditional loops deterministically false conditions (#1428, @ME0265). checks unreachable code inside , else, , , repeat blocks, including combinations break next statements. (#2105, @ME0265). implicit_assignment_linter() gains argument allow_lazy (default FALSE) allows optionally skipping lazy assignments like && (B <- foo()) (#2016, @MichaelChirico). unused_import_linter() gains argument interpret_glue (default TRUE) paralleling object_usage_linter() toggle whether glue::glue() expressions inspected exported object usage (#2042, @MichaelChirico). default_undesirable_functions updated also include Sys.unsetenv() structure() (#2192 #2228, @IndrajeetPatil @MichaelChirico). brace_linter() pipe_call_linter() pipe_continuation_linter() unnecessary_concatenation_linter() unnecessary_placeholder_linter() brace_linter() function_left_parentheses_linter() indentation_linter() object_length_linter() object_name_linter() package_hooks_linter() paren_body_linter() unnecessary_lambda_linter() unreachable_code_linter()","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-positives-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false positives","title":"lintr 3.1.1","text":"pipe-aware, particular removing false positives around piping {stringr} functions like x |> str_replace(fixed(\"\"), \"b\") (#1811, @MichaelChirico). Ignores non-string inputs pattern= keyword argument (#2159, @MichaelChirico). T_and_F_symbol_linter() for_loop_index_linter() literal_coercion_linter() object_name_linter() undesirable_function_linter() unreachable_code_linter() yoda_test_linter() sprintf_linter() pipe-aware, x %>% sprintf(fmt = \"%s\") longer lints (#1943, @MichaelChirico). condition_message_linter() ignores usages extracted calls like env$stop(paste(, b)) (#1455, @MichaelChirico). inner_combine_linter() longer throws length-1 calls c() like c(exp(2)) c(log(3)) (#2017, @MichaelChirico). usage discouraged unnecessary_concatenation_linter(), inner_combine_linter() per se apply. sort_linter() lints order() single vector, excluding e.g. x[order(x, y)] x[order(y, x)] (#2156, @MichaelChirico). redundant_ifelse_linter() aware dplyr::if_else()’s missing= argument, if_else(, TRUE, FALSE, missing = FALSE) doesn’t lint, if_else(, TRUE, FALSE, NA) (#1941, @MichaelChirico). Note dplyr::coalesce() tidyr::replace_na() may still preferable.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-negatives-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false negatives","title":"lintr 3.1.1","text":"unreachable_code_linter() finds unreachable code even presence comment semicolon return() stop() (#2127, @MEO265). finds assignments call arguments besides first one (#2136, @MichaelChirico). finds assignments parenthetical expressions like (&& (B <- foo())) { } (#2138, @MichaelChirico). thanks @Bisaloo @strengejacke detecting regression original fix (#2231, #2247).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-310","dir":"Changelog","previous_headings":"","what":"lintr 3.1.0","title":"lintr 3.1.0","text":"CRAN release: 2023-07-19","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecations--breaking-changes-3-1-0","dir":"Changelog","previous_headings":"","what":"Deprecations & Breaking Changes","title":"lintr 3.1.0","text":".lintr files can now kept directory .github/linters better compatibility Super-Linter. Note may breaking change already config .github/linters inside subdirectory well R project’s root, since former now discovered first ignored . Please see vignette(\"lintr\") details configs discovered (#1746, @tonyk7440 @klmr). single_quotes_linter() deprecated favor generalizable quotes_linter() (#1729, @MichaelChirico). unneeded_concatentation_linter() deprecated favor unnecessary_concatenation_linter() naming consistency (#1707, @IndrajeetPatil). consecutive_stopifnot_linter() deprecated favor general (see ) consecutive_assertion_linter() (#1604, @MichaelChirico). no_tab_linter() deprecated favor whitespace_linter() naming consistency future generalization (#1954, @MichaelChirico). available_linters() prioritizes tags exclude_tags case overlap, .e., tags listed arguments included, excluded. don’t expect many people affected , old behavior made explicit documentation, make note since required changing test lintr’s suite linters_with_tags() implicitly assumed behavior. lint(), lint_dir(), lint_package() longer accept certain arguments (cache= lint(), relative_path= latter two) positionally. warning() since 3.0.0 upgraded error.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-1-0","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.1.0","text":"linters_with_tags() now includes previously missing spaces around “” listing missing linters advertised available_linters(). error message may appear e.g. update lintr version new linters don’t restart R session (#1946, @Bisaloo) fixed_regex_linter() robust errors stemming unrecognized escapes (#1545, #1845, @IndrajeetPatil). get_source_expressions() can handle Sweave/Rmarkdown documents reference chunks like <> (#779, @MichaelChirico). Note simply skipped, rather attempting retrieve reference also lint . assignment_linter() longer lints assignments braces include comments allow_trailing = FALSE (#1701, @ashbaldry) object_usage_linter() longer silently ignores usage warnings don’t contain quoted name (#1714, @AshesITR) longer fails code comments inside multi-line call glue::glue() (#1919, @MichaelChirico) namespace_linter() correctly recognizes backticked operators exported respective namespaces (like rlang::`%||%`) (#1752, @IndrajeetPatil) lint_package() correctly finds package within subdir path points anywhere within package (#1759, @AshesITR) Improved error behavior Lint(), lint() xml_nodes_to_lints() (#1427, #763, @AshesITR) Lint() validates inputs thoroughly, preventing errors print.Lints like “Error rep.int(character, length) : invalid ‘times’ value:”. lint() longer tries create expression tree unexpected end input errors, can broken. xml_nodes_to_lints() warns can’t find lint locations uses dummy locations fallback. linters_with_defaults() longer erroneously marks linter factories linters (#1725, @AshesITR). Row names available_linters() data frame now contiguous (#1781, @IndrajeetPatil). object_name_linter() allows S3 group Generics (see ?base::groupGeneric) S3 generics defined different file package (#1808, #1841, @AshesITR) object_usage_linter() improves identification exact source lint undefined variables expressions variable used symbol usual way, example formula extraction $ (#1914, @MichaelChirico). general usage warnings without location info (#1986 #1917, @AshesITR) function_left_parentheses_linter() produces specific lint (longer fails) opening parenthesis different line function call name (#1953, @MichaelChirico). Thanks also @IndrajeetPatil @lorenzwalthert identifying regression initial fix, #1963.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-defaults-3-1-0","dir":"Changelog","previous_headings":"","what":"Changes to defaults","title":"lintr 3.1.0","text":"Set default except argument duplicate_argument_linter() c(\"mutate\", \"transmute\"). allows sequential updates like x |> mutate(= b + 1, = log()) (#1345, @IndrajeetPatil). object_usage_linter() gains skip_with argument skip code () expressions. consistent R CMD check, defaults TRUE (#941, #1458, @IndrajeetPatil). Handles backticked symbols inside {glue} expressions correctly, e.g. glue(\"{`x`}\") correctly determines x used (#1619, @MichaelChirico) Detects problems inside R4.1.0+ lambda functions (\\(...)) (#1933, @MichaelChirico) spaces_inside_linter() allows terminal missing keyword arguments (e.g. alist(arg = ); #540, @MichaelChirico) brace_linter() allows empty braced expression line (e.g. (updating_condition()) { }) regardless allow_single_line match corresponding behavior {styler}. expedient style guide handling case awaits clarification: https://github.com/tidyverse/style/issues/191. (#1346, @MichaelChirico) undesirable_function_linter() undesirable_operator_linter() now produce error empty vector undesirable functions operators provided (#1867, @IndrajeetPatil). New linters also included defaults (see “New linters” details): indentation_linter() quotes_linter() unnecessary_concatenation_linter() whitespace_linter() lint_package() also looks files exec/ (#1950, @jmaspons).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-3-1-0","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr 3.1.0","text":"New get_r_string() helper get R-equivalent value string, especially useful R-4-style raw strings. Previously internal lintr helper, now exported facilitate writing custom linters (#1493, @MichaelChirico). object_usage_linter() improves lint metadata detecting undefined infix operators, e.g. %>% := (#1497, @MichaelChirico) unused_import_linter() can detect datasets imported packages longer warns package imported datasets (#1545, @IndrajeetPatil). linter triggers error, lint() provide actionable summary error occurred, particularly useful cases like lint_package() responsible file responsible linter unknown (@MichaelChirico). Typically, linters cause R stop – syntax errors lead error lints, example. Please report failures likely bugs. pipe_continuation_linter() recognizes violations involving native R pipe |> (#1609, @MichaelChirico) paste_linter() also catches usages like paste(rep(\"*\", 10L), collapse = \"\") can written concisely strrep(\"*\", 10L) (#1108, @MichaelChirico) spaces_inside_linter() produces lints spaces inside [[ (#1673, @IndrajeetPatil). sprintf_linter() also applies gettextf() (#1677, @MichaelChirico) Documentation linters contains examples code produce lints (#1492, @IndrajeetPatil). implicit_integer_linter() gains parameter allow_colon skip lints expressions like 1:10 (#1155, @MichaelChirico) infix_spaces_linter() supports native R pipe |> (#1793, @AshesITR) unnecessary_concatenation_linter() (f.k.. unneeded_concatenation_linter()) longer lints c(...) (.e., passing ... function call) allow_single_expression = FALSE (#1696, @MichaelChirico) object_name_linter() gains parameter regexes allow custom naming conventions (#822, #1421, @AshesITR) literal_coercion_linter() reports replacement lint message, e.g. code like .integer(1) suggest using 1L instead, code like .numeric(NA) suggest using NA_real_ instead (#1439, @MichaelChirico) Added format() functions lint lints (#1784, @AshesITR) all_linters() function provides easy way access available linters (#1843, @IndrajeetPatil) missing_argument_linter() allows missing arguments quote() calls (#1889, @IndrajeetPatil). get_source_expressions() correctly extracts indented code chunks R Markdown documents, helps avoid spurious lints related whitespace (#1945, @MichaelChirico). convention taken , within chunk, code anchored relative leftmost non-whitespace column. available_linters() gives priority tags exclude_tags case overlap. particular, means available_linters(tags = \"deprecated\") work return deprecated linters without needing specify exclude_tags (#1959, @MichaelChirico). {lintr} configuration file now searched system’s user configuration path; lintr config filename can also configured explicitly setting environment variable R_LINTR_LINTER_FILE (#460, @klmr) Errors {lintr} configuration file now produce informative error messages (#886, @AshesITR)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-3-1-0","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr 3.1.0","text":"matrix_apply_linter() recommends use dedicated rowSums(), colSums(), colMeans(), rowMeans() apply(., MARGIN, sum) apply(., MARGIN, mean). recommended alternative much efficient readable (#1869, @Bisaloo). unnecessary_lambda_linter(): detect unnecessary lambdas (anonymous functions), e.g. lapply(x, function(xi) sum(xi)) can lapply(x, sum) purrr::map(x, ~quantile(.x, 0.75, na.rm = TRUE)) can purrr::map(x, quantile, 0.75, na.rm = TRUE). Naming probs = 0.75 can improve readability (#1531, #1866, @MichaelChirico, @Bisaloo). redundant_equals_linter() redundant comparisons TRUE FALSE like is_treatment == TRUE (#1500, @MichaelChirico) lengths_linter() encouraging usage lengths(x) instead sapply(x, length) (similar) function_return_linter() handling issues function return() statements. Currently handles assignments within return() clause, e.g. return(x <- foo()) (@MichaelChirico) boolean_arithmetic_linter() identifying places logical aggregations appropriate, e.g. length((x == y)) == 0 !(x == y) even (x != y) (@MichaelChirico) for_loop_index_linter() prevent overwriting local variables loop declared like (x x) { ... } (@MichaelChirico) is_numeric_linter() redundant checks equivalent .numeric(x) .numeric(x) || .integer(x) class(x) %% c(\"numeric\", \"integer\") (@MichaelChirico) empty_assignment_linter() identifying empty assignments like x = {} clearly written x = NULL (@MichaelChirico) unnecessary_placeholder_linter() identifying usage {magrittr} placeholder . omitted (@MichaelChirico) routine_registration_linter() identifying native routines don’t use registration (useDynLib NAMESPACE; @MichaelChirico) indentation_linter() checking indentation conforms 2-space Tidyverse-style (@AshesITR @dgkf, #1411, #1792, #1898). unnecessary_nested_if_linter() checking unnecessary nested statements single statement appropriate conditional expression suffice (@IndrajeetPatil @AshesITR, #1778). implicit_assignment_linter() checking implicit assignments function calls (@IndrajeetPatil @AshesITR, #1777). quotes_linter() generalized version (now deprecated) single_quotes_linter(). accepts argument delimiter specify whether \" ' accepted method delimiting character literals. default, \", reflects Tidyverse style guide recommendation matches behavior single_quotes_linter(). unnecessary_concatenation_linter() simply unneeded_concatenation_linter(), renamed. consecutive_assertion_linter() (f.k.. consecutive_stopifnot_linter()) now lints consecutive calls assertthat::assert_that() (long msg= argument used; #1604, @MichaelChirico). whitespace_linter() simply no_tab_linter(), renamed. future, plan extend work different whitespace preferences.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"notes-3-1-0","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr 3.1.0","text":"{lintr} now depends R version 3.5.0, line tidyverse policy R version compatibility. lint() continues support Rmarkdown documents. users custom .Rmd engines, e.g. marginformat {tufte} theorem {bookdown}, note engines must registered {knitr} prior running lint() order {lintr} behave expected, .e., shown part knitr::knit_engines$get(). {tufte} {bookdown} particular, one needs load package namespace accomplish (.e., minimally loadNamespace(\"tufte\") loadNamespace(\"bookdown\"), respectively, register packages’ custom engines; since library() also runs loadNamespace(), running library() also work). Note {tufte} added code .onLoad() recently request (see https://github.com/rstudio/tufte/issues/117). Therefore, ensure ’re using recent version get behavior described {tufte}. generally, requirement loadNamespace() register package’s custom {knitr} engines, may need work package authors figure solution engines. Thanks Yihui developers helpful discussions around issue (#797, @IndrajeetPatil). output lint() Lint() gain S3 class \"list\" assist S3 dispatch (#1494, @MichaelChirico) corollary, now register as_tibble method class lints, conditional {tibble} availability, avoid dispatching list method work lint() output (#1997, @MichaelChirico) object_usage_linter() gives helpful warning glue() expression fails evaluate (#1985, @MichaelChirico) documentation object_name_linter() now describes \"symbols\" works passed styles parameter (#1924, @hedsnz).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-302","dir":"Changelog","previous_headings":"","what":"lintr 3.0.2","title":"lintr 3.0.2","text":"CRAN release: 2022-10-19 Fix test avoid leaving behind cache files global cache directory.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-301","dir":"Changelog","previous_headings":"","what":"lintr 3.0.1","title":"lintr 3.0.1","text":"CRAN release: 2022-09-13 Skip multi-byte tests non UTF-8 locales (#1504) modify_defaults() longer uses mistaken \"lintr_function\" S3 class, instead applying \"linter\" class also common Linter(). Linter() also includes \"function\" S3 class output facilitate S3 dispatch function methods appropriate (#1392, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-defaults-3-0-1","dir":"Changelog","previous_headings":"","what":"Changes to defaults","title":"lintr 3.0.1","text":"brace_linter() allows opening curly braces new line comment ending preceding line (#1433 #1434, @IndrajeetPatil). seq_linter() produces lint seq(...), since also properly handle empty edge cases (#1468, @IndrajeetPatil). seq_linter() additionally lints 1:n() ({dplyr}) 1:.N ({data.table}) (#1396, @IndrajeetPatil). literal_coercion_linter() lints {rlang}’s atomic vector constructors (.e., int(), chr(), lgl(), dbl()) argument scalar (#1437, @IndrajeetPatil). redundant_ifelse_linter()’s lint message correctly suggests negation yes condition 0 (#1432, @IndrajeetPatil). seq_linter() provides specific replacement code lint message (#1475, @IndrajeetPatil).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-3-0-1","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr 3.0.1","text":"New sort_linter() detect x[order(x)] recommend faster clearer alternative: sort(x) (#1528, @Bisaloo) unreachable_code_linter() ignores trailing comments match closing nolint block (#1347, @AshesITR). New function_argument_linter() enforce arguments defaults appear last function declarations, see Tidyverse design guide (#450, @AshesITR). New allow_trailing argument added assignment_linter() check assignment operators end line, value following line (#1491, @ashbaldry) New sarif_output() function output lints SARIF output (#1424, @shaopeng-gh) commented_code_linter() now lints commented argument code, containing trailing comma, well (#386, @AshesITR). example comment containing # na.rm = TRUE, now triggers lint.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-0-1","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.0.1","text":"object_length_linter() fail case dependencies exports (e.g. data-packages) (#1424, #1509, @IndrajeetPatil). get_source_expressions() longer fails R files match knitr pattern (#743, #879, #1406, @AshesITR). Parse error lints now appear linter name \"error\" instead NA (#1405, @AshesITR). Also, linting longer runs source_expressions contain invalid string data cause error messages linters. linters. Prevent lint() hanging Rmd files syntax errors (#1443, @MichaelChirico). get_source_expressions() longer omits trailing non-code lines knitr files (#1400, #1415, @AshesITR). fixes location information trailing_blank_lines_linter() RMarkdown documents without terminal newlines. vignette(\"lintr\") incorrectly cited exclude key setting file exclusions .lintr actually exclusions. (#1401, @AshesITR) Fixed file exclusion detection lint_dir() longer errors multiple exclusions global exclusions configured single file (#1413, #1442, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"other-changes-3-0-1","dir":"Changelog","previous_headings":"","what":"Other changes","title":"lintr 3.0.1","text":"minimum needed version soft dependency withr bumped 2.5.0 (#1404, @IndrajeetPatil). Changed deprecation warning with_defaults() also mention modify_defaults() (#1438, @AshesITR). Quarto files (.qmd) supported box. documentation testing infrastructure updated reflect (#1486, @IndrajeetPatil).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-300","dir":"Changelog","previous_headings":"","what":"lintr 3.0.0","title":"lintr 3.0.0","text":"CRAN release: 2022-06-13","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"breaking-changes-3-0-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"lintr 3.0.0","text":"linters now function factories (.e., functions return functions) consistency. Previously, linters customizable parameters factories (#245, @fangly, @AshesITR, @MichaelChirico). means usage lint(\"file.R\", seq_linter) updated lint(\"file.R\", seq_linter()), following update custom linters: Exclusions specified .lintr file now relative location file support excluding entire directories (#158, #438, @AshesITR). Removed long-deprecated linters (’ve marked deprecated since v1.0.1 2017): absolute_paths_linter() camel_case_linter() multiple_dots_linter() snake_case_linter() trailing_semicolons_linter() Removed return() all_undesirable_functions early returns (often improve readability reduce code complexity) require explicit use return(). Follow #1100 upcoming return_linter() lint unnecessary return() statements (#1146, @AshesITR). Note can replicate old behavior supplying return custom undesirable function: undesirable_function_linter(c(all_undesirable_functions, list(return = NA)))","code":"my_custom_linter <- function(source_expression) { ... } # becomes my_custom_linter <- function() Linter(function(source_expression) { ... })"},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecations-3-0-0","dir":"Changelog","previous_headings":"","what":"Deprecations","title":"lintr 3.0.0","text":"Lints now marked name linter caused instead name implementation function. Deprecated obsolete linter argument Lint() (#664, #673, #746, @AshesITR). Downstream custom linters follow suit. Renamed semicolon_terminator_linter() semicolon_linter() better consistency. semicolon_terminator_linter() survives marked deprecation. new linter also new signature, taking arguments allow_compound allow_trailing replace old single argument semicolon, signature consistency linters. closed_curly_linter() open_curly_linter() paren_brace_linter() lint(), ... now 3rd argument, earlier cache. lint_dir() lint_package(), ... now 2nd argument, earlier relative_path. Deprecated argument source_file exported functions with_id() ids_with_token(). renamed source_expression better reflect argument typically output get_source_expressions(). now, old argument source_file can still used (warning). now-private functional versions many linters also underwent renaming (source_file -> source_expression). direct effect packages importing lintr, mentioned case custom linters imitating lintr style also adopted source_file naming want adapt keep sync. Deprecated with_defaults() favor linters_with_defaults(), add modify_defaults() intended used generally modify (.e., extend, trim, /update) list defaults. Note argument corresponding with_defaults()’s default= called defaults= (.e., pluralized) , usage like with_defaults(default = NULL, ...) converted linters_with_defaults(defaults = list(), ...) (#1029, #1336, #1361, @AshesITR @michaelchirico). Deprecated find_line() find_column() helpers item-level expressions returned get_source_expressions(). helpers typically associated regex-based logic building linters, rarely needed prone false positives; now lintr almost exclusively uses XPath-based logic linters, longer necessary (#1373, @MichaelChirico).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"updates-to-default_linters-3-0-0","dir":"Changelog","previous_headings":"Other changes to defaults","what":"Updates to default_linters","title":"lintr 3.0.0","text":"closed_curly_linter(); now also allow }] addition }) }, exceptions, .e., } doesn’t need line paired closing square bracket, closing parenthesis, comma. Also improved lint metadata source markers land closing brace instead closing parenthesis improve experience fixing lint (#583, @AshesITR). open_curly_linter(); also longer lint unnecessary trailing whitespace (use trailing_whitespace_linter() ) also allow (, ,, %>% preceding lines exceptions, .e., { can alone line previous line terminated opening parenthesis, comma, pipe (%>%) (#487, #1028, @AshesITR). paren_brace_linter(); brace_linter() also lints /else repeat missing whitespace. Require else come line preceding }, present (#884, @MichaelChirico). Require functions spanning multiple lines use curly braces (#987, @MichaelChirico). Require balanced usage {} /else conditions, .e., branch uses braces, must else branch, vice versa (#983, @MichaelChirico). New paren_body_linter() checks space right parenthesis body expression (#809, @kpagacz). Added semicolon_linter() default enforces tidyverse style guide rule (#683, @AshesITR). Right assignments now linted default (-> ->>). New argument allow_cascading_assign (TRUE default) toggles whether lint <<- ->>. New argument allow_right_assign (FALSE default) toggles whether lint -> ->>. commented_code_linter(): use parse tree find comments, eliminating false positives (#451, @AshesITR). Extended lint x != NA (, == caught) NA == x (, NA RHS caught). Extended skip usages comments like .na(x) # use .na(x), x == NA. function_left_parentheses_linter(): improved location information (#1266, #1267, @AshesITR). Added argument allow_multiple_spaces (TRUE default) toggles whether generate lint operators used multiple spaces, e.g. x + 2. default setting allows extra spacing used increase line--line alignment (#940, @f-ritter @MichaelChirico). Extended usages like ~b function(=1) { ... } linted (#930, #michaelchirico). Added argument exclude_operators disable lints selected infix operators. default, “low-precedence” operators throw lints; see ?infix_spaces_linter enumeration . (#914, @MichaelChirico). Add exception / usage box::use() declarations (#1087, @klmr). line_length_linter(): place source marker margin affected line improve user experience de-linting – just press Return (#735, @AshesITR).* no_tab_linter(): use reliable matching (e.g., excluding matches found comments; #441, @russHyde). object_length_linter(): correctly detect generics count implementation class towards length. prevents false positive lints case long generic names, e.g. very_very_very_long_generic_name.short_class longer produces lint (#871, @AshesITR). Improved generic detection – user-defined method my_method.upstream.class, upstream.class longer throws lint generic (my_method) properly uses snake_case (#737, @AshesITR). Exclude special R namespace hook functions .onLoad() (#500, #614, @AshesITR @MichaelChirico). Correctly detect imported functions linting packages (#642, @AshesITR). Correctly detect assignment generics like names<-.class_name (#843, @jonkeane). \"symbols\" new default style won’t lint -symbol object names. particular, means operator names like %+% allowed. longer lints names used $ extractions (#582, @AshesITR). Detect global variables top-level dollar-assignments (#666, @AshesITR). Report usage warnings spanning multiple lines (#507, @AshesITR). Detect usages inside glue::glue() constructs (#942, @AshesITR). Extended include functions assigned = instead <- (#1081, @MichaelChirico). Detect functions exported packages explicitly attached using library() require() calls (#1127, @AshesITR). Improved location information cases previous regex-based approach didn’t work, e.g. unicode characters variable names (#1285, @AshesITR). Correctly detect functions declared within assign() setMethod() (#1322, @AshesITR). spaces_inside_linter(): ignore spaces preceding trailing comments (#636, @MichaelChirico). Added default enforces tidyverse style guide rule (#517, @AshesITR). longer lint occurrences T F used subsetting, give better message used variable names (#657, @AshesITR). Extended lint files without terminal newline (#675, @AshesITR). Also, running lint() file without terminal newline longer throws warning(). Extended also lint completely blank lines default (#1044, @AshesITR). Added argument allow_empty_lines (FALSE default) toggle behavior. Improved trailing whitespace inside string literals trigger lint (#1045, @AshesITR). Added argument allow_in_strings (TRUE default) toggle behavior. browser() debug() debugcall() debugonce() trace() untrace() longer lints library() require() calls attaching package undesired name, e.g. library(foo) (#814, @kpagacz @MichaelChirico). longer lints undesirable symbols used names $ extractions (#1050, @AshesITR). Added explanation certain functions might undesirable alternatives use; ditto undesirable_operator_linter() (#1133, #1146, #1159, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"other-noteworthy-changes-3-0-0","dir":"Changelog","previous_headings":"Other changes to defaults","what":"Other noteworthy changes","title":"lintr 3.0.0","text":"cyclocomp_linter(): set default complexity_limit 15. brings default sync enforced via default_linters (#693, @AshesITR). lint_package() now lints files demo directory default (#703, @dmurdoch). Moved default lintr cache directory ~/.R/lintr_cache (violation CRAN policy) R_user_dir(\"lintr\", \"cache\"). Note 3.0.0 major version update invalidates old cache anyway, can safely deleted (#1062, @AshesITR).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-3-0-0","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr 3.0.0","text":"backport_linter() detecting mismatched R version dependencies (#506, #1316, #1318, #1319, @MichaelChirico @AshesITR). duplicate_argument_linter() similarly checks duplicate arguments supplied function calls (#850, @renkun-ken). missing_argument_linter() check empty (missing) arguments function calls (#563, #1152, @renkun-ken @AshesITR). missing_package_linter() check packages calls library() friends missing (#536, #1037, @renkun-ken @MichaelChirico). namespace_linter() check common mistakes pkg::symbol usages (#548, @renkun-ken). package_hooks_linter() run series checks also done R CMD check .onLoad(), .onAttach(), .Last.lib() .onDetach() hooks (#882, @MichaelChirico). pipe_call_linter() enforce steps magrittr pipelines use explicit calls instead symbols, e.g. x %>% mean() instead x %>% mean (#801, @MichaelChirico). sprintf_linter() check common mistakes sprintf() usage (#544, #624, @renkun-ken @AshesITR). unused_import_linter() detect unnecessary library() calls R scripts (#239, @jimhester, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"google-linters-3-0-0","dir":"Changelog","previous_headings":"New and improved features > New linters","what":"Google linters","title":"lintr 3.0.0","text":"Google heavy user lintr internally, developed large set linters improving code consistency correcting common R usage mistakes. release includes many linters general interest broader R community. included future releases. See, e.g. #884, #979, #998, #1011, #1016, #1036, #1051, #1066, #1067; special thanks @MichaelChirico @michaelquinn32. any_duplicated_linter() Require usage anyDuplicated(x) > 0L (duplicated(x)) similar. any_is_na_linter() Require usage anyNA(x) (.na(x)). class_equals_linter() Prevent comparing class(x) ==, !=, %%, inherits() typically preferred. condition_message_linter() Prevent condition messages constructed like stop(paste(...)) (just stop(...) preferable). conjunct_test_linter() Require usage expect_true(x); expect_true(y) expect_true(x && y) similar. consecutive_stopifnot_linter() Require consecutive calls stopifnot() unified one. expect_comparison_linter() Require usage expect_gt(x, y) expect_true(x > y) similar. expect_identical_linter() Require usage expect_identical() default, expect_equal() exception. expect_length_linter() Require usage expect_length(x, n) expect_equal(length(x), n) similar. expect_named_linter() Require usage expect_named(x, n) expect_equal(names(x), n) similar. expect_not_linter() Require usage expect_false(x) expect_true(!x), vice versa. expect_null_linter() Require usage expect_null(x) expect_equal(x, NULL) similar. expect_s3_class_linter() Require usage expect_s3_class(x, k) expect_equal(class(x), k) similar. expect_s4_class_linter() Require usage expect_s4_class(x, k) expect_true(methods::(x, k)). expect_true_false_linter() Require usage expect_true(x) expect_equal(x, TRUE) similar. expect_type_linter() Require usage expect_type(x, t) expect_equal(typeof(x), t) similar. Added parameter allow_grepl (default FALSE) toggle whether grepl() usages linted. might treated separately grepl(\"^x\", NA) FALSE; startsWith() equivalent get FALSE missing input clunkier, explicit: !.na(x) & startsWith(x, string) (#1376, @MichaelChirico). ifelse_censor_linter() Require usage pmax() / pmin() appropriate, e.g. ifelse(x > y, x, y) pmax(x, y). inner_combine_linter() Require inputs known-vectorized functions combined first rather later, e.g. .Date(c(x, y)) c(.Date(x), .Date(y)). literal_coercion_linter() Require using correctly-typed literals instead direct coercion, e.g. 1L instead .numeric(1). nested_ifelse_linter() Prevent nested calls ifelse() like ifelse(, x, ifelse(B, y, z)), similar. numeric_leading_zero_linter() Require leading 0 fractional numeric constants, e.g. 0.1 instead .1. outer_negation_linter() Require usage !(x) (!x) !(x) (!x). paste0() encouraged instead paste(sep = \"\"). toString() glue::glue_collapse() encouraged instead paste(x, collapse = \", \"). Lint sep= passed paste0() – typically mistake. redundant_ifelse_linter() Prevent usage like ifelse(& B, TRUE, FALSE) ifelse(C, 0, 1) (latter .numeric(!C)). regex_subset_linter() Require usage grep(ptn, x, value = TRUE) x[grep(ptn, x)] similar. string_boundary_linter() Require usage startsWith(x, ptn) grepl(\"^ptn\", x) substr(x, 1, 3) == ptn similar. strings_as_factors_linter() Check code designed work stringsAsFactors = FALSE default change R 4.0 examining code data.frame() usages susceptible assumptions default value stringsAsFactors=. system_file_linter() Prevent usage like file.path(system.file(\"\", package = \"pkg\"), \"B\") simply system.file(\"\", \"B\", package = \"pkg\") concise readable. unreachable_code_linter() Prevent code return() stop() statements never reached (extended #1051 thanks early user testing, thanks @bersbersbers!). vector_logic_linter() Require use scalar logical operators (&& ||) inside () conditions similar. yoda_test_linter() Require usage expect_identical(x, 1L) expect_equal(1L, x) similar.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"other-features-and-improvements-3-0-0","dir":"Changelog","previous_headings":"New and improved features","what":"Other features and improvements","title":"lintr 3.0.0","text":"linter help page. ?linters also links tag help pages, collecting linters similar goal. linter can multiple tags. available_linters(): new function list available linters tags. feature extensible package authors providing add-linters {lintr}. available_tags(): new function list available tags. linters_with_tags(): new function help build list linters using tags. Encodings: lintr now supports non-system character Encodings. correct encoding auto-detected .Rproj DESCRIPTION files project. Override default encoding setting lintr (#752, #782, @AshesITR). Jenkins CI: Support writing comments GitHub repo running Jenkins CI (#488, @fdlk). Performance: Optimized performance-critical functions lintr, get_source_expressions() resulting 2x speedup test suite even complex files (#1169, #1197, #1200, #1201, #1214, @MichaelChirico @AshesITR). Average lint_package() execution time 30% median package sees 40% improvement. Raw strings: Several linters tightened internal logic allow raw strings like R\"( \\string )\" (#1034, #1285, @MichaelChirico @AshesITR). Added linter name lintrs output facilitate discovery correct name (#1357, @AshesITR). Improved S3 generic detection non-standard S3 generics UseMethod() called several preceding expressions (#846, @jonkeane). extraction_operator_linter(): longer lint x[NULL] (#1273, @AshesITR). is_lint_level(): new exported helper readably explaining type expression required custom linter. linters written require full file’s parse tree (example, single_quotes_linter()). Others need single expressions, cache-friendly (linters written way leverage caching) (#921, @MichaelChirico). lint_dir() excludes renv packrat directories default (#697, @AshesITR). lint(): new optional argument text supplying line lines directly, e.g. file already memory linting done ad hoc (#503, @renkun-ken). seq_linter(): improve lint message clearer reason linting (#522, @MichaelChirico). Correctly considers arguments pipelines (%>% |>; #573, #1270, @michaelquinn32 @AshesITR). New argument allow_single_expression, default TRUE, toggling whether c(x) linted, .e., call c() one entry constant. cases, c() can simply dropped, e.g. c(:b); others, parentheses still needed, e.g. -c(:b) -(:b); still others, c() used side-effect stripping attributes, e.g. c(factor(letters)) c(matrix(1:10, 5, 2)). last case, c() can () cases replaced .vector() .integer() readability. fact, suspect always preferable , may change default allow_single_expression = FALSE future. Please report use case .vector() suit needs (#1344, @MichaelChirico). use_lintr(): new exported helper creating minimal .lintr configuration (#902, @AshesITR). xml_nodes_to_lints(): new exported helper converting xml_node objects obtained using linter logic expressed XPath Lint objects (#1124, #1216, #1234, @MichaelChirico @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-0-0","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.0.0","text":"RStudio: Source markers cleared lints (#520, @AshesITR). Error message mismatched starts ends exclusion ranges now helpful. (#571, #860, @AshesITR @danielinteractive). Improved location information R parse errors (#894, #892, @renkun-ken @AshesITR). Fix possible error invalid XML produced xmlparsedata::xml_parse_data() (#559, @renkun-ken). Fix handling zero-length variable name error (#566, @renkun-ken). Malformed Rmd files now cause lint instead error (#571, @AshesITR). longer fails getParseData() returns truncated (invalid) Unicode character parsed text (#815, @leogama). Fixes text value STR_CONST nodes involving 1- 2-width octal escapes (e.g. \"\\1\") account R parser bug (https://bugs.r-project.org/show_bug.cgi?id=18323; #1056, @MichaelChirico). Handle Rmd inputs containing unevaluated code blocks named format specifiers (#472, @russHyde). line_length_linter(): fix bug causing duplicate lints lines containing multiple expressions (#681, @AshesITR). Warns returns NULL package found (instead giving peculiar error message; #776, @MichaelChirico). Stricter considered package – folders named DESCRIPTION ignored (#702, @MichaelChirico). longer duplicates lintr_function class already present (#511, @AshesITR). Warns named argument NULL name defaults (#1049, @AshesITR). linters_with_defaults() handles automatic naming long arguments correctly (#774, @MichaelChirico). save_cache() now recursively create cache directory; avoids errors arise parent directories exist (#60, @dankessler). spaces_left_parentheses_linter(): fix bug causing warnings like “parent == parent[before_operator_idx] longer object length multiple shorter object length” nested expressions (#654, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"internals-3-0-0","dir":"Changelog","previous_headings":"","what":"Internals","title":"lintr 3.0.0","text":"Added new, restrictive test workflow - test-package - fails warnings emitted tests (#1263, #1272, @AshesITR). Added secondary, restrictive lint workflow - lint-changed-files - newly written / modified code (#641, @dragosmg). Several optional Imported packages become Suggested dependencies: httr, testthat, rstudioapi. allow snappier CI builds usages relying “peripheral” features package. Special thanks @bersbersbers early testing 3.0.0 changes. Switched CI Travis GitHub Actions, using full tidyverse recommended R CMD check. Code coverage linting implemented using separate GitHub Actions workflows (#572, @dragosmg). Updated R CMD GitHub Actions workflow check R 3.6 Ubuntu, instead R 3.3, R 4.0 Windows, instead R 3.6 (#803, @ dragosmg). lintr now uses 3rd edition testthat (@MichaelChirico, @AshesITR, #910, #967).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-201","dir":"Changelog","previous_headings":"","what":"lintr 2.0.1","title":"lintr 2.0.1","text":"CRAN release: 2020-02-19","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-features-2-0-1","dir":"Changelog","previous_headings":"","what":"New features","title":"lintr 2.0.1","text":"lintr now supports GitHub Actions print lints warning messages lints printed action. lint_package() now lint vignettes data-raw default (#447, @AshesITR). lint_dir() now include Rmd Rnw files default (@AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"minor-fixes-and-features-2-0-1","dir":"Changelog","previous_headings":"","what":"Minor fixes and features","title":"lintr 2.0.1","text":"single_quote_linter() longer causes print issue open quote appears column > close quote (#457, @jamieRowen) absolute_path_linter() nonportable_path_linter() now handle file-paths wrapped double-quotes (#433, #437, @russHyde). get_source_expressions() changed handle expr_or_assign_or_help tokens arising parsing code containing equals-assignments R-devel (#403, #456, @russHyde). object_usage_linter changed ensure lint-position indicated relative start file, rather start defining function (#432, @russHyde). commas_linter now allows spaces come comma used denote fall-switch statement (#499, @MrMallIronmaker)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-200","dir":"Changelog","previous_headings":"","what":"lintr 2.0.0","title":"lintr 2.0.0","text":"CRAN release: 2019-10-01 lintr 2.0.0 major release, incorporates development changes since last major release (1.0.0) 2016-04-16.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecated-functions-2-0-0","dir":"Changelog","previous_headings":"","what":"Deprecated functions","title":"lintr 2.0.0","text":"Deprecated camel_case_linter(), snake_case_linter() multiple_dots_linter() favor object_name_linter() enforce given style: snake_case, dotted.case, lowerCamelCalse, UpperCamelCase, alllowercase ALLUPPERCASE (#59, @fangly). Deprecated absolute_paths_linter() favor new absolute_path_linter(), lax mode fewer false positive lints (#199, @fangly).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-2-0-0","dir":"Changelog","previous_headings":"","what":"New linters","title":"lintr 2.0.0","text":"New cyclocomp_linter() identifies overly complex functions (#361, @fabian-s) New equals_na_linter() (#143, #326, @jabranham) New extraction_operator_linter() checks [[ operator used extracting single element object, [ (subsetting) $ (interactive use) (@fangly). New function_left_parentheses_linter() check space function name left parentheses (#204, @jrnold). New implicit_integer_linter() detects round numbers declared integers, .e. 1 instead 1L (@fangly). New nonportable_path_linter() identifies paths constructed without file.path() (@fangly). New paren_brace_linter() checks space right parenthesis opening curly brace (@bfgray3, #242). New pipe_continuation_linter() ensure space %>% newline afterwards (#216). expressions (#181, @fangly). New seq_linter(), finds 1:length(...) (similar) expressions (#155, 1) New todo_comment_linter() lints TODOs (@fangly). New T_and_F_symbol_linter() warns using T F instead TRUE FALSE (@fangly). New undesirable_operator_linter() undesirable_function_linter() lint uses user-specified functions operators (#48, #149, @fangly). New unneeded_concatenation_linter() lints uses c() constant arguments (@fangly).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-functions-for-writing-linters-2-0-0","dir":"Changelog","previous_headings":"","what":"New functions for writing linters","title":"lintr 2.0.0","text":"Export expect_lint() (#178, #210) Export ids_with_token() with_id() (#297 @stufield) linters can use XML parse tree well now, via https://github.com/MangoTheCat/xmlparsedata package (#154, 1)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-functions-for-users-2-0-0","dir":"Changelog","previous_headings":"","what":"New functions for users","title":"lintr 2.0.0","text":"New lint_dir() function lint files given directory (@arekbee, #360) New summary.lints() function summarize linter results (#260, #262, @wlandau). New checkstyle_output() function output lints checkstyle XML output (#156, @joshkgold)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"linter-fixes-2-0-0","dir":"Changelog","previous_headings":"","what":"Linter fixes","title":"lintr 2.0.0","text":"closed_curly_linter() now allows closing parenthesis comma closing curly brace (#167, @Enchufa2) commas_linter() now handles missing arguments calls properly (#145) commented_code_linter() now relaxed, longer lints comments within roxygen blocks consider “-” R operator avoid many false positives. function_left_parentheses_linter() now allows spaces function starts left parenthesis (#311) no_tab_linter() now reports proper line cases (#134, @fangly) object_length_linter() argument length now defaults 30 consistency (#325 @DragosMG) object_name_linter() now works passed multiple styles (#341, @infotroph) object_usage_linter() changed better detect lexical scoping global variables (#27, #336, #91, #382) object_usage_linter() now respects utils::globalVariables(), can used avoid false positive warnings due non-standard evaluation (#352) object_usage_linter() now ignores top level calls contain function definitions (#26). object_linter*()s now lint objects declared current file (#76, #108, #136, #191, #194, #201, @fangly). open_curly_linter() closed_curly_linter() now lint double curly syntax (#388) open_curly_linter() now allows comments curly braces (#188) pipe_continuation_linter() now behaves better nested expressions, functions etc. (#366 @russHyde) space_inside_linter() now reports proper line column numbers (#203, @fangly)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"general-improvements-and-fixes-2-0-0","dir":"Changelog","previous_headings":"","what":"General improvements and fixes","title":"lintr 2.0.0","text":"expect_lint() now longer shows Rstudio markers error messages correctly preserved (#180, #211, @fangly) Lint() / .data.frame() error now fixed (#179, @fangly). lint() longer errors inline \\\\Sexpr (#127). lint() longer errors ‘<% %>’ constructs (#185). lint_package() now works cache, intended (#146, @schloerke) lint_package() now excludes R/RcppExports.R default (#282) lint_package() now removes fully excluded files soon possible lintr now looks configuration parent directories well package directory (#238, #345) seq_linter now one default linters (#316). Fix issue lintr’s compatibility R-devel, due new version PCRE library (#411.) read_settings() now better error message config file end newline (#160, #189) expect_lint_free() now automatically skipped run covr (#287) Now lintr tries generate comments running wercker travis CI (#166) Add support overriding GitHub API Token via GITHUB_TOKEN environment variable (#63, @mattyb) Config files now also searched users’ home directory (#266, @randy3k) Fixed crash caused ambiguous cache file paths (#212, @fangly). RStudio addins lint current source project (fixes #264, @JhossePaul) Added proper handling tab characters (fixes #44, @fangly) lintr need igraph package (#152, 1) Fixed cache saved directory requested (#213, @fangly) avoid reading pre-processing ignored files (@mwaldstein) Allow number # start comment. Useful ESS (#299, @prosoitos) R Markdown files contain chunks longer treated code (#370). Fixed plain-code-block bug Rmarkdown (#252, @russHyde) Fixed bug non-R chunks using {lang} engine format parsed R-markdown (#322, @russHyde) Ensured lintr runs / installs / tests R-3.6: pinned github xmlparsedata; ensure vectors length-1 compared using && || (#363 #377 #384 #391, @russHyde).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-103","dir":"Changelog","previous_headings":"","what":"lintr 1.0.3","title":"lintr 1.0.3","text":"CRAN release: 2018-11-08 Fix tests work changes parser R 3.6","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-102","dir":"Changelog","previous_headings":"","what":"lintr 1.0.2","title":"lintr 1.0.2","text":"CRAN release: 2017-11-08 Fix tests work upcoming testthat release.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-101","dir":"Changelog","previous_headings":"","what":"lintr 1.0.1","title":"lintr 1.0.1","text":"CRAN release: 2017-08-10 bugfix work knitr 1.16.7 expect_lint_free() now always skipped CRAN. necessary non-binary R source may available running tests CRAN, tests may run package directory.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-100","dir":"Changelog","previous_headings":"","what":"lintr 1.0.0","title":"lintr 1.0.0","text":"CRAN release: 2016-04-16 bugfix work testthat 1.0.0","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-033","dir":"Changelog","previous_headings":"","what":"lintr 0.3.3","title":"lintr 0.3.3","text":"CRAN release: 2015-09-15 infix_spaces_linter now properly checks = named arguments. (#130, @saurfang). commas_linter now properly recognizes lints preceded blank line points missing space rather comma (#111, #129, @saurfang). Make spaces_left_parentheses_linter robust determining ( type (#128, @saurfang) commented_code_linter (#83, @jackwasey) Now trims long comments (#55, reported @paulstaab) Automatic commenting Github commits pull requests linting Travis-CI expect_lint_free expectation can added testthat unit tests. Robust configuration system exclusion logic Emacs Sublime Text 3 plugins now available respective package repositories. add names.lints, split.lints (#49, @ttriche) Fixed bug caused vim syntastic plugin work properly windows (#46, @abossenbroek) allow lintr customization per project using .lintr config files. use globalenv() instead baseenv() default parent environment methods included. check object usage eval fails. Fixes (#24, reported @fabian-s) trailing_whitespace_linter reporting incorrect line number Use RStudio source marker API display lints (#37, @jjallaire) Permit single quotes quote literal double quotes (#28, @jackwasey) # nolint comments respected caching (#68, @krlmlr) Properly handle knitr document formats Allow (( linting (#259, @nathaneastwood) Remove ^ infix spaces conform tidyverse. (#302, @nathaneastwood)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-020","dir":"Changelog","previous_headings":"","what":"lintr 0.2.0","title":"lintr 0.2.0","text":"CRAN release: 2014-12-01 Initial release","code":""}] +[{"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. #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 81 characters. X = 42L # nolint ------ this comment overflows the default 80 chars line length."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-only-some-linters","dir":"Articles","previous_headings":"Exclusions","what":"Excluding only some linters","title":"Using lintr","text":"file3.R > lint(\"file3.R\") Observe object_name_linter suppressed. preferable blanket # nolint statements blanket exclusions may accidentally silence linter intentionally suppressed. Multiple linters can specified listing comma separator: file4.R > lint(\"file4.R\") can also specify linter names unique prefix instead full name: file5.R > lint(\"file5.R\")","code":"X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 94 characters. X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-multiple-lines-of-codes","dir":"Articles","previous_headings":"Exclusions","what":"Excluding multiple lines of codes","title":"Using lintr","text":"linters disabled contiguous block code, exclude_start exclude_end patterns can used. default # nolint start # nolint end respectively. # nolint start accepts syntax # nolint disable specific linters following lines # nolint end encountered. (lints)","code":"# x <- 42L # print(x) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Remove commented code. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[commented_code_linter] Remove commented code. # 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() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[T_and_F_symbol_linter] Use TRUE instead of the symbol T. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[T_and_F_symbol_linter] Use FALSE instead of the symbol F. lint( text = \"T = 1.2; F = 2.4\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[T_and_F_symbol_linter] Don't use T as a variable name, as it can break code relying on T being TRUE. #> ::warning file=,line=1,col=11::file=,line=1,col=11,[T_and_F_symbol_linter] Don't use F as a variable name, as it can break code relying on F being FALSE. # okay lint( text = \"x <- c(TRUE, FALSE)\", linters = T_and_F_symbol_linter() ) lint( text = \"t = 1.2; f = 2.4\", linters = T_and_F_symbol_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Absolute path linter — absolute_path_linter","title":"Absolute path linter — absolute_path_linter","text":"Check absolute paths used (e.g. \"/var\", \"C:\\System\", \"~/docs\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Absolute path linter — absolute_path_linter","text":"","code":"absolute_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Absolute path linter — absolute_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Absolute path linter — absolute_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Absolute path linter — absolute_path_linter","text":"","code":"# will produce lints lint( text = 'R\"--[/blah/file.txt]--\"', linters = absolute_path_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[absolute_path_linter] Do not use absolute paths. # okay lint( text = 'R\"(./blah)\"', linters = absolute_path_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on all available linters — all_linters","title":"Create a linter configuration based on all available linters — all_linters","text":"Create linter configuration based available linters","code":""},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"all_linters(..., packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on all available linters — all_linters","text":"... 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). lint( text = \"length(unique(x)) == length(x)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). # okay lint( text = \"anyDuplicated(x)\", linters = any_duplicated_linter() ) lint( text = \"anyDuplicated(x) == 0L\", linters = any_duplicated_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"anyNA() exists replacement (.na(x)) efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"any_is_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"# will produce lints lint( text = \"any(is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). lint( text = \"any(is.na(foo(x)))\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). # okay lint( text = \"anyNA(x)\", linters = any_is_na_linter() ) lint( text = \"anyNA(foo(x))\", linters = any_is_na_linter() ) lint( text = \"any(!is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Assignment linter — assignment_linter","title":"Assignment linter — assignment_linter","text":"Check <- always used assignment.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assignment linter — assignment_linter","text":"","code":"assignment_linter( allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE, allow_pipe_assign = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Assignment linter — assignment_linter","text":"allow_cascading_assign Logical, default TRUE. FALSE, <<- ->> allowed. allow_right_assign Logical, default FALSE. TRUE, -> ->> allowed. allow_trailing Logical, default TRUE. FALSE assignments allowed end lines. allow_pipe_assign Logical, default FALSE. TRUE, magrittr's %<>% assignment allowed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Assignment linter — assignment_linter","text":"configurable, consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Assignment linter — assignment_linter","text":"","code":"# will produce lints lint( text = \"x = mean(x)\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not ->, for assignment. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[assignment_linter] Replace ->> by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. lint( text = \"x %<>% as.character()\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Avoid the assignment pipe %<>%; prefer using <- and %>% separately. # okay lint( text = \"x <- mean(x)\", linters = assignment_linter() ) code_lines <- \"x <- 1\\ny <<- 2\" writeLines(code_lines) #> x <- 1 #> y <<- 2 lint( text = code_lines, linters = assignment_linter() ) # customizing using arguments code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter(allow_right_assign = TRUE) ) lint( text = \"x <<- 1\", linters = assignment_linter(allow_cascading_assign = FALSE) ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Replace <<- by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. writeLines(\"foo(bar = \\n 1)\") #> foo(bar = #> 1) lint( text = \"foo(bar = \\n 1)\", linters = assignment_linter(allow_trailing = FALSE) ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[assignment_linter] Assignment = should not be trailing at the end of a line. lint( text = \"x %<>% as.character()\", linters = assignment_linter(allow_pipe_assign = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Linter metadata from a package — available_linters","title":"Get Linter metadata from a package — available_linters","text":"available_linters() obtains tagged list Linters available package. available_tags() searches available tags.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Linter metadata from a package — available_linters","text":"","code":"available_linters(packages = \"lintr\", tags = NULL, exclude_tags = \"deprecated\") available_tags(packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Linter metadata from a package — available_linters","text":"packages character vector packages search linters. tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. exclude_tags Tags exclude results. Linters least one matching tag returned. 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\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] trimws (R 3.2.0) is not available for dependency R >= 3.0.0. lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] str2lang (R 3.6.0) is not available for dependency R >= 3.2.0. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). lint( text = \"sum(grepl(pattern, x)) == 0\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). # okay lint( text = \"!any(x == y)\", linters = boolean_arithmetic_linter() ) lint( text = \"!any(grepl(pattern, x))\", linters = boolean_arithmetic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Brace linter — brace_linter","title":"Brace linter — brace_linter","text":"Perform various style checks related placement spacing curly braces:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Brace linter — brace_linter","text":"","code":"brace_linter(allow_single_line = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Brace linter — brace_linter","text":"allow_single_line TRUE, allow open closed curly pair line.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Brace linter — brace_linter","text":"Opening curly braces never line always followed newline. Opening curly braces space . Closing curly braces line unless followed else. Closing curly braces conditions line corresponding else. Either neither branch /else use curly braces, .e., either branches use {...} neither . Functions spanning multiple lines use curly braces.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Brace linter — brace_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Brace linter — brace_linter","text":"","code":"# will produce lints lint( text = \"f <- function() { 1 }\", linters = brace_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line. #> ::warning file=,line=1,col=21::file=,line=1,col=21,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. writeLines(\"if (TRUE) {\\n return(1) }\") #> if (TRUE) { #> return(1) } lint( text = \"if (TRUE) {\\n return(1) }\", linters = brace_linter() ) #> ::warning file=,line=2,col=12::file=,line=2,col=12,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. # okay writeLines(\"f <- function() {\\n 1\\n}\") #> f <- function() { #> 1 #> } lint( text = \"f <- function() {\\n 1\\n}\", linters = brace_linter() ) writeLines(\"if (TRUE) { \\n return(1) \\n}\") #> if (TRUE) { #> return(1) #> } lint( text = \"if (TRUE) { \\n return(1) \\n}\", linters = brace_linter() ) # customizing using arguments writeLines(\"if (TRUE) { return(1) }\") #> if (TRUE) { return(1) } lint( text = \"if (TRUE) { return(1) }\", linters = brace_linter(allow_single_line = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Checkstyle Report for lint results — checkstyle_output","title":"Checkstyle Report for lint results — checkstyle_output","text":"Generate report linting results using Checkstyle XML format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Checkstyle Report for lint results — checkstyle_output","text":"","code":"checkstyle_output(lints, filename = \"lintr_results.xml\")"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Checkstyle Report for lint results — checkstyle_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block comparison of class with == — class_equals_linter","title":"Block comparison of class with == — class_equals_linter","text":"Usage like class(x) == \"character\" prone error since class R general vector. correct version S3 classes inherits(): inherits(x, \"character\"). Often, class k . equivalent, example .character() .data.frame().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block comparison of class with == — class_equals_linter","text":"","code":"class_equals_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block comparison of class with == — class_equals_linter","text":"Similar reasoning applies class(x) %% \"character\".","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block comparison of class with == — class_equals_linter","text":"best_practices, consistency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block comparison of class with == — class_equals_linter","text":"","code":"# will produce lints lint( text = 'is_lm <- class(x) == \"lm\"', linters = class_equals_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with ==. lint( text = 'if (\"lm\" %in% class(x)) is_lm <- TRUE', linters = class_equals_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with %in%. # 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() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[commas_linter] Remove spaces before a comma. lint( text = \"mean(x,trim = 0.2,na.rm = TRUE)\", linters = commas_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[commas_linter] Put a space after a comma. #> ::warning file=,line=1,col=19::file=,line=1,col=19,[commas_linter] Put a space after a comma. lint( text = \"x[ ,, drop=TRUE]\", linters = commas_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commas_linter] Remove spaces before a comma. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Put a space after a comma. lint( text = \"x[1,]\", linters = commas_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Put a space after a comma. # 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() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Remove commented code. lint( text = \"x <- f() # g()\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[commented_code_linter] Remove commented code. lint( text = \"x + y # + z[1, 2]\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[commented_code_linter] Remove commented code. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[comparison_negation_linter] Use x != y, not !(x == y). lint( text = \"!(x > 2)\", linters = comparison_negation_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[comparison_negation_linter] Use x <= y, not !(x > y). # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. lint( text = \"stop('test', call. = TRUE)\", linters = condition_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. lint( text = \"stop('test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(.) to display the call in an error message. lint( text = \"stop('this is a', 'test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(.) to display the call in an error message. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste to build stop strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). lint( text = 'warning(paste0(\"a string\", \" another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste0 to build warning strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). # okay lint( text = 'stop(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(paste(\"a string\", \"another\", sep = \"-\"))', linters = condition_message_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Configurable linters — configurable_linters","title":"Configurable linters — configurable_linters","text":"Generic linters support custom configuration needs.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Configurable linters — configurable_linters","text":"following linters tagged 'configurable': absolute_path_linter assignment_linter backport_linter brace_linter 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"expect_false(x || (y && z))\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] 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. lint( text = \"stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))\", linters = conjunct_test_linter(allow_named_stopifnot = FALSE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Write multiple conditions like stopifnot(A, B) instead of stopifnot(A && B). The latter will produce better error messages in the case of failure. lint( text = \"dplyr::filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=23::file=,line=1,col=23,[conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). lint( text = \"filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=16::file=,line=1,col=16,[conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to stopifnot(). lint( text = \"assert_that(x); assert_that(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to assert_that(). # okay lint( text = \"stopifnot(x, y)\", linters = consecutive_assertion_linter() ) lint( text = 'assert_that(x, msg = \"Bad x!\"); assert_that(y)', linters = consecutive_assertion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=1,col=25::file=,line=1,col=25,[consecutive_mutate_linter] Unify consecutive calls to mutate(). # 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) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 2 to at most 1. # 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() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[duplicate_argument_linter] Avoid duplicate arguments in function calls. lint( text = \"fun(arg = 1, arg = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[duplicate_argument_linter] Avoid duplicate arguments in function calls. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. writeLines(\"x = {\\n}\") #> x = { #> } lint( text = \"x = {\\n}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. # okay lint( text = \"x <- { 3 + 4 }\", linters = empty_assignment_linter() ) lint( text = \"x <- NULL\", linters = empty_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality check with NA linter — equals_na_linter","title":"Equality check with NA linter — equals_na_linter","text":"Check x == NA, x != NA x %% NA. usage almost surely incorrect -- checks missing values done .na().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality check with NA linter — equals_na_linter","text":"","code":"equals_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Equality check with NA linter — equals_na_linter","text":"common_mistakes, correctness, default, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality check with NA linter — equals_na_linter","text":"","code":"# will produce lints lint( text = \"x == NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of x == NA lint( text = \"x != NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of x != NA lint( text = \"x %in% NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y). lint( text = \"expect_true(x <= y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y). lint( text = \"expect_true(x == (y == 2))\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y). # okay lint( text = \"expect_gt(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_lte(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_identical(x, y == 2)\", linters = expect_comparison_linter() ) lint( text = \"expect_true(x < y | x > y^2)\", linters = expect_comparison_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter enforces usage testthat::expect_identical() default expectation comparisons testthat suite. expect_true(identical(x, y)) equivalent unadvised method test. , testthat::expect_equal() used expect_identical() inappropriate, .e., x y need numerically equivalent instead fully identical (case, provide tolerance= argument expect_equal() explicitly). also applies inconvenient check full equality (e.g., names can ignored, case ignore_attr = \"names\" supplied expect_equal() (, 2nd edition, check.attributes = FALSE).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"expect_identical_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter allows expect_equal() three circumstances: named argument set (e.g. ignore_attr tolerance) Comparison made explicit decimal, e.g. expect_equal(x, 1.0) (implicitly setting tolerance) ... passed (wrapper functions might set arguments ignore_attr tolerance)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. lint( text = \"expect_true(identical(x, y))\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. # okay lint( text = \"expect_identical(x, y)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, check.attributes = FALSE)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, tolerance = 1e-6)\", linters = expect_identical_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"testthat::expect_length() exists specifically testing length() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"expect_length_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n) # okay lint( text = \"expect_length(x, 2L)\", linters = expect_length_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint expectation — expect_lint","title":"Lint expectation — expect_lint","text":"expectation 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n) # okay lint( text = 'expect_named(x, \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(colnames(x), \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(dimnames(x), \"a\")', linters = expect_named_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"testthat::expect_false() exists specifically testing output FALSE. testthat::expect_true() can also used tests negating output, better use tailored function instead. reverse also true -- use expect_false() instead expect_true(!).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"expect_not_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa. # okay lint( text = \"expect_false(x)\", linters = expect_not_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_null for checking NULL — expect_null_linter","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"Require usage expect_null(x) expect_equal(x, NULL) similar usages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"expect_null_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"testthat::expect_null() exists specifically testing NULL objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_equal(x, NULL) lint( text = \"expect_identical(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_identical(x, NULL) lint( text = \"expect_true(is.null(x))\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_true(is.null(x)) # okay lint( text = \"expect_null(x)\", linters = expect_null_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s3_class() — expect_s3_class_linter","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"testthat::expect_s3_class() exists specifically testing class S3 objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"expect_s3_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. lint( text = 'expect_equal(class(x), \"numeric\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. # okay lint( text = 'expect_s3_class(x, \"data.frame\")', linters = expect_s3_class_linter() ) lint( text = 'expect_type(x, \"double\")', linters = expect_s3_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"testthat::expect_s4_class() exists specifically testing class S4 objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"expect_s4_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s4_class_linter] expect_s4_class(x, k) is better than expect_true(is(x, k)). Note also expect_s3_class() available for testing S3 objects. # okay lint( text = 'expect_s4_class(x, \"Matrix\")', linters = expect_s4_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"testthat::expect_true() testthat::expect_false() exist specifically testing TRUE/FALSE value object. testthat::expect_equal() testthat::expect_identical() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"expect_true_false_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE) lint( text = \"expect_equal(x, FALSE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE) # okay lint( text = \"expect_true(x)\", linters = expect_true_false_linter() ) lint( text = \"expect_false(x)\", linters = expect_true_false_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"testthat::expect_type() exists specifically testing storage type objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"expect_type_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"best_practices, package_development, 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t) lint( text = 'expect_identical(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t) # okay lint( text = 'expect_type(x, \"double\")', linters = expect_type_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[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. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter(allow_unescaped = TRUE) ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. code_lines <- 'stringr::str_subset(x, \"\\\\\\\\$\")' writeLines(code_lines) #> stringr::str_subset(x, \"\\\\$\") lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[fixed_regex_linter] 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. lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. # 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() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. lint( text = \"for (x in foo(x, y)) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. # okay lint( text = \"for (xi in x) { TRUE }\", linters = for_loop_index_linter() ) lint( text = \"for (col in DF$col) { TRUE }\", linters = for_loop_index_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function argument linter — function_argument_linter","title":"Function argument linter — function_argument_linter","text":"Check arguments defaults come last function declarations, per tidyverse design guide. Changing argument order can breaking change. alternative changing argument order instead set default arguments NULL.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function argument linter — function_argument_linter","text":"","code":"function_argument_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function argument linter — function_argument_linter","text":"best_practices, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function argument linter — function_argument_linter","text":"","code":"# will produce lints lint( text = \"function(y = 1, z = 2, x) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[function_argument_linter] Arguments without defaults should come before arguments with defaults. lint( text = \"function(x, y, z = 1, ..., w) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=28::file=,line=1,col=28,[function_argument_linter] Arguments without defaults should come before arguments with defaults. # okay lint( text = \"function(x, y = 1, z = 2) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, w, z = 1, ...) {}\", linters = function_argument_linter() ) lint( text = \"function(y = 1, z = 2, x = NULL) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, z = 1, ..., w = NULL) {}\", linters = function_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function left parentheses linter — function_left_parentheses_linter","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Check left parentheses function call spaces (e.g. mean (1:3)). Although syntactically valid, makes code difficult read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"function_left_parentheses_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Exceptions made control flow functions (, , etc.).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function left parentheses linter — function_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"mean (x)\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. lint( text = \"stats::sd(c (x, y, z))\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. # okay lint( text = \"mean(x)\", linters = function_left_parentheses_linter() ) lint( text = \"stats::sd(c(x, y, z))\", linters = function_left_parentheses_linter() ) lint( text = \"foo <- function(x) (x + 1)\", linters = function_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"return(x <- ...) either distracting (x ignored), confusing (assigning x side effect muddled dual-purpose expression).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"function_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"# will produce lints lint( text = \"foo <- function(x) return(y <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. lint( text = \"foo <- function(x) return(x <<- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. writeLines(\"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\") #> e <- new.env() #> foo <- function(x) return(e$val <- x + 1) lint( text = \"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=2,col=27::file=,line=2,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. # okay lint( text = \"foo <- function(x) return(x + 1)\", linters = function_return_linter() ) code_lines <- \" foo <- function(x) { x <<- x + 1 return(x) } \" lint( text = code_lines, linters = function_return_linter() ) code_lines <- \" e <- new.env() foo <- function(x) { e$val <- x + 1 return(e$val) } \" writeLines(code_lines) #> #> e <- new.env() #> foo <- function(x) { #> e$val <- x + 1 #> return(e$val) #> } #> lint( text = code_lines, linters = function_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract text from STR_CONST nodes — get_r_string","title":"Extract text from STR_CONST nodes — get_r_string","text":"Convert STR_CONST text() values R strings. useful account arbitrary character literals, 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/RtmpgA7L92/file17c117be6fee\" #> #> $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/RtmpgA7L92/file17c117be6fee\" #> #> $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/RtmpgA7L92/file17c117be6fee\" #> #> $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() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[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. lint( text = \"if (!A) x else if (!B) y else z\", linters = if_not_else_linter() ) #> ::warning file=,line=1,col=20::file=,line=1,col=20,[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. lint( text = \"ifelse(!is_treatment, x, y)\", linters = if_not_else_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[if_not_else_linter] Prefer `ifelse(A, x, y)` to the less-readable `ifelse(!A, y, x)`. lint( text = \"if (!is.null(x)) x else 2\", linters = if_not_else_linter(exceptions = character()) ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[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. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. 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) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[if_switch_linter] Prefer repeated if/else statements over overly-complicated switch() statements. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmin(x, y) is preferable to ifelse(x < y, x, y). lint( text = \"ifelse(x > 0, x, 0)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmax(x, y) is preferable to ifelse(x > y, x, y). # okay lint( text = \"pmin(5:1, pi)\", linters = ifelse_censor_linter() ) lint( text = \"pmax(x, 0)\", linters = ifelse_censor_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Avoid implicit assignment in function calls — implicit_assignment_linter","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"Assigning inside function calls makes code difficult read, avoided, except functions capture side-effects (e.g. capture.output()).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"implicit_assignment_linter( except = c(\"bquote\", \"expression\", \"expr\", \"quo\", \"quos\", \"quote\"), 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() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. lint( text = \"mean(x <- 1:4)\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. # 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() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers. lint( text = \"x[2]\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=4::file=,line=1,col=4,[implicit_integer_linter] Use 2L or 2.0 to avoid implicit integers. lint( text = \"1:10\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[implicit_integer_linter] Use 10L or 10.0 to avoid implicit integers. # okay lint( text = \"x <- 1.0\", linters = implicit_integer_linter() ) lint( text = \"x <- 1L\", linters = implicit_integer_linter() ) lint( text = \"x[2L]\", linters = implicit_integer_linter() ) lint( text = \"1:10\", linters = implicit_integer_linter(allow_colon = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that indentation is consistent — indentation_linter","title":"Check that indentation is consistent — indentation_linter","text":"Check indentation consistent","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that indentation is consistent — indentation_linter","text":"","code":"indentation_linter( indent = 2L, hanging_indent_style = c(\"tidy\", \"always\", \"never\"), assignment_as_infix = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that indentation is consistent — indentation_linter","text":"indent Number spaces, code block indented relative parent code block. Used multi-line code blocks ({ ... }), function calls (( ... )) extractions ([ ... ], [[ ... ]]). Defaults 2. hanging_indent_style Indentation style multi-line function calls arguments first line. Defaults tidyverse style, .e. block indent used function call terminates ) separate line hanging indent . Note function multi-line function calls without arguments first line always expected block-indented arguments. hanging_indent_style \"tidy\", multi-line function definitions expected double-indented first line function definition contains arguments closing parenthesis line. assignment_as_infix Treat <- regular (.e. left-associative) infix operator? means, infix operators right hand side assignment trigger second level indentation:","code":"# complies to any style map( x, f, additional_arg = 42 ) # complies to \"tidy\" and \"never\" map(x, f, additional_arg = 42 ) # complies to \"always\" map(x, f, additional_arg = 42 ) # complies to \"tidy\" and \"always\" map(x, f, additional_arg = 42) # complies to \"never\" map(x, f, additional_arg = 42) # complies to \"tidy\" function( a, b) { # body } # complies to any style variable <- a %+% b %+% c # complies to assignment_as_infix = TRUE variable <- a %+% b %+% c # complies to assignment_as_infix = FALSE variable <- a %+% b %+% c"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check that indentation is consistent — indentation_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check that indentation is consistent — indentation_linter","text":"","code":"# will produce lints code_lines <- \"if (TRUE) {\\n1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=0::file=,line=2,col=0,[indentation_linter] Indentation should be 2 spaces but is 0 spaces. code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"always\") ) #> ::warning file=,line=2,col=2::file=,line=2,col=2,[indentation_linter] Hanging indent should be 4 spaces but is 2 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"never\") ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. # okay code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter() ) code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter(indent = 4) )"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Infix spaces linter — infix_spaces_linter","title":"Infix spaces linter — infix_spaces_linter","text":"Check infix operators surrounded spaces. Enforces corresponding Tidyverse style guide rule; see https://style.tidyverse.org/syntax.html#infix-operators.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"infix_spaces_linter(exclude_operators = NULL, allow_multiple_spaces = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Infix spaces linter — infix_spaces_linter","text":"exclude_operators Character vector operators exclude consideration linting. Default include following \"low-precedence\" operators: +, -, ~, >, >=, <, <=, ==, !=, &, &&, |, ||, <-, :=, <<-, ->, ->>, =, /, *, infix operator (exclude infixes passing \"%%\"). Note \"=\" 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() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators. lint( text = \"1:4 %>%sum()\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[infix_spaces_linter] Put spaces around all infix operators. # okay lint( text = \"x <- 1L\", linters = infix_spaces_linter() ) lint( text = \"1:4 %>% sum()\", linters = infix_spaces_linter() ) code_lines <- \" ab <- 1L abcdef <- 2L \" writeLines(code_lines) #> #> ab <- 1L #> abcdef <- 2L #> lint( text = code_lines, linters = infix_spaces_linter(allow_multiple_spaces = TRUE) ) lint( text = \"a||b\", linters = infix_spaces_linter(exclude_operators = \"||\") ) 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[inner_combine_linter] Combine inputs to vectorized functions first to take full advantage of vectorization, e.g., log10(c(x, y)) only runs the more expensive log10() once as compared to c(log10(x), log10(y)). # okay lint( text = \"log10(c(x, y, z))\", linters = inner_combine_linter() ) lint( text = \"c(log(x, base = 10), log10(x, base = 2))\", linters = inner_combine_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":null,"dir":"Reference","previous_headings":"","what":"Is this an expression- or a file-level source object? — is_lint_level","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"Helper determining whether current source_expression contains expressions current file, just single expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"is_lint_level(source_expression, level = c(\"expression\", \"file\"))"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"source_expression parsed expression object, .e., element object returned get_source_expressions(). level level expression tested? \"expression\" means individual expression, \"file\" means expressions current file available.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"tmp <- 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = 'class(z) %in% c(\"numeric\", \"integer\")', linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] 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. # 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() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[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). lint( text = \"data.frame(`a` = 1)\", linters = keyword_quote_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[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). lint( text = 'my_list$\"key\"', linters = keyword_quote_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[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. lint( text = 's4obj@\"key\"', linters = keyword_quote_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[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. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[length_levels_linter] nlevels(x) is better than 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[length_test_linter] Checking the length of a logical vector is likely a mistake. Did you mean `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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"vapply(x, length, integer(1L))\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"purrr::map_int(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. # okay lint( text = \"lengths(x)\", linters = lengths_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=3,col=1::file=,line=3,col=1,[library_call_linter] Move all library calls to the top of the script. lint( text = \"library('dplyr', character.only = TRUE)\", linters = library_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[library_call_linter] Use symbols in library calls to avoid the need for 'character.only'. 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() ) #> ::warning file=,line=2,col=1::file=,line=2,col=1,[library_call_linter] Call library() directly, not vectorized with sapply(). code <- \"suppressMessages(library(dplyr))\\nsuppressMessages(library(tidyr))\" writeLines(code) #> suppressMessages(library(dplyr)) #> suppressMessages(library(tidyr)) lint( text = code, linters = library_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[library_call_linter] Unify consecutive calls to suppressMessages(). You can do so by writing all of the calls in one braced expression like suppressMessages({...}). # 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) ) #> ::warning file=,line=1,col=21::file=,line=1,col=21,[line_length_linter] Lines should not be more than 20 characters. This line is 23 characters. # okay lint( text = strrep(\"x\", 21L), linters = line_length_linter(length = 40L) )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a lint object — lint-s3","title":"Create a lint object — lint-s3","text":"Create lint object","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a lint object — lint-s3","text":"","code":"Lint( filename, line_number = 1L, column_number = 1L, type = c(\"style\", \"warning\", \"error\"), message = \"\", line = \"\", ranges = NULL, linter = \"\" )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a lint object — lint-s3","text":"filename path source file linted. line_number line number lint occurred. column_number column number lint occurred. type type lint. message message used describe lint error line code source lint occurred ranges list ranges line emphasized. linter deprecated. longer used.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a lint object — lint-s3","text":"object class c(\"lint\", \"list\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint a file, directory, or package — lint","title":"Lint a file, directory, or package — lint","text":"lint() lints single file. lint_dir() lints files directory. lint_package() lints likely locations R files package, .e. R/, tests/, inst/, vignettes/, data-raw/, demo/, exec/.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint a file, directory, or package — lint","text":"","code":"lint( filename, linters = NULL, ..., cache = FALSE, parse_settings = TRUE, text = NULL ) lint_dir( path = \".\", ..., relative_path = TRUE, exclusions = list(\"renv\", \"packrat\"), pattern = \"(?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 #> ::warning file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2::file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2::file=/tmp/RtmpgA7L92/file17c12cedbe30,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators. lint(\"a = 123\\n\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. lint(text = \"a = 123\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use 1L instead of int(1), i.e., use literals directly where possible, instead of coercion. lint( text = \"as.character(NA)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use NA_character_ instead of as.character(NA), i.e., use literals directly where possible, instead of coercion. lint( text = \"rlang::lgl(1L)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use TRUE instead of rlang::lgl(1L), i.e., use literals directly where possible, instead of coercion. # okay lint( text = \"1L\", linters = literal_coercion_linter() ) lint( text = \"NA_character_\", linters = literal_coercion_linter() ) lint( text = \"TRUE\", linters = literal_coercion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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()) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[number_linter] This is a number. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[number_linter] This is a number."},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"colSums() rowSums() clearer performant alternatives apply(x, 2, sum) apply(x, 1, sum) respectively case 2D arrays, matrices","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"matrix_apply_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"# will produce lints lint( text = \"apply(x, 1, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(x) rather than apply(x, 1, sum) lint( text = \"apply(x, 2, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x)) or colSums(x) if x has 2 dimensions rather than apply(x, 2, sum) lint( text = \"apply(x, 2, sum, na.rm = TRUE)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x, na.rm = TRUE)) or colSums(x, na.rm = TRUE) if x has 2 dimensions rather than apply(x, 2, sum, na.rm = TRUE) lint( text = \"apply(x, 2:4, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x), dims = 3) or colSums(x) if x has 4 dimensions rather than apply(x, 2:4, sum)"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing argument linter — missing_argument_linter","title":"Missing argument linter — missing_argument_linter","text":"Check missing arguments function calls (e.g. stats::median(1:10, )).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing argument linter — missing_argument_linter","text":"","code":"missing_argument_linter( except = c(\"alist\", \"quote\", \"switch\"), allow_trailing = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Missing argument linter — missing_argument_linter","text":"except character vector function names exceptions. allow_trailing always allow trailing empty arguments?","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing argument linter — missing_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing argument linter — missing_argument_linter","text":"","code":"# will produce lints lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[missing_argument_linter] Missing argument 2 in function call. # okay lint( text = 'tibble(x = \"a\")', linters = missing_argument_linter() ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(except = \"tibble\") ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(allow_trailing = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing package linter — missing_package_linter","title":"Missing package linter — missing_package_linter","text":"Check missing packages library(), require(), loadNamespace(), requireNamespace() calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing package linter — missing_package_linter","text":"","code":"missing_package_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing package linter — missing_package_linter","text":"common_mistakes, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing package linter — missing_package_linter","text":"","code":"# will produce lints lint( text = \"library(xyzxyz)\", linters = missing_package_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[missing_package_linter] Package 'xyzxyz' is not installed. # okay lint( text = \"library(stats)\", linters = missing_package_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify lintr defaults — modify_defaults","title":"Modify lintr defaults — modify_defaults","text":"Modify list defaults name, allowing replacement, deletion addition new elements.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify lintr defaults — modify_defaults","text":"","code":"modify_defaults(defaults, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify lintr defaults — modify_defaults","text":"defaults named list elements modify. ... arguments elements change. unnamed, argument automatically named. named argument already exists defaults, replaced new element. exist, added. value NULL, element removed.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify lintr defaults — modify_defaults","text":"modified list elements, sorted name. achieve sort platform-independent way, two transformations applied names: (1) replace _ 0 (2) convert tolower().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Modify lintr defaults — modify_defaults","text":"","code":"# custom list of undesirable functions: # remove `sapply` (using `NULL`) # add `cat` (with an accompanying message), # add `print` (unnamed, i.e. with no accompanying message) # add `source` (as taken from `all_undesirable_functions`) my_undesirable_functions <- modify_defaults( defaults = default_undesirable_functions, sapply = NULL, \"cat\" = \"No cat allowed\", \"print\", all_undesirable_functions[[\"source\"]] ) # list names of functions specified as undesirable names(my_undesirable_functions) #> [1] \".libPaths\" \"attach\" \"browser\" \"cat\" #> [5] \"debug\" \"debugcall\" \"debugonce\" \"detach\" #> [9] \"library\" \"mapply\" \"options\" \"par\" #> [13] \"print\" \"require\" \"setwd\" \"sink\" #> [17] \"source\" \"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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[namespace_linter] Package 'xyzxyz' is not installed. lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[namespace_linter] 'ssd' is not exported from {stats}. # okay lint( text = \"stats::sd(c(1, 2, 3))\", linters = namespace_linter() ) lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter(check_exports = FALSE) ) lint( text = \"stats:::ssd(c(1, 2, 3))\", linters = namespace_linter(check_nonexports = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of nested ifelse() calls — nested_ifelse_linter","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Calling ifelse() nested calls problematic two main reasons: can hard read -- mapping code expected output code can messy task/require lot mental bandwidth, especially code nests inefficient -- ifelse() can evaluate arguments yes (see https://stackoverflow.com/q/16275149); issue exacerbated nested calls","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"nested_ifelse_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Users can instead rely readable alternative modeled SQL CASE statements. 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() ) #> ::warning file=,line=1,col=22::file=,line=1,col=22,[nested_ifelse_linter] Don't use nested ifelse() calls; instead, try (1) data.table::fcase; (2) dplyr::case_when; or (3) using a lookup table. # okay lint( text = 'dplyr::case_when(x == \"a\" ~ 1L, x == \"b\" ~ 2L, TRUE ~ 3L)', linters = nested_ifelse_linter() ) lint( text = 'data.table::fcase(x == \"a\", 1L, x == \"b\", 2L, default = 3L)', linters = nested_ifelse_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/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() ) #> ::warning file=,line=2,col=14::file=,line=2,col=14,[nested_pipe_linter] Don't nest pipes inside other calls. lint( text = \"df1 %>% inner_join(df2 %>% select(a, b))\", linters = nested_pipe_linter(allow_inline = FALSE) ) #> ::warning file=,line=1,col=20::file=,line=1,col=20,[nested_pipe_linter] Don't nest pipes inside other calls. 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() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[nonportable_path_linter] Use file.path() to construct portable file paths. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"nrow(filter(x, is_treatment))\", linters = nrow_subset_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"x %>% filter(x, is_treatment) %>% nrow()\", linters = nrow_subset_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. # 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() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[numeric_leading_zero_linter] Include the leading zero for fractional numeric constants. lint( text = \"x <- -.1\", linters = numeric_leading_zero_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[numeric_leading_zero_linter] Include the leading zero for fractional numeric constants. # 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() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[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. lint( text = \"x[nchar(x) > 0]\", linters = nzchar_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[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. # 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) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_length_linter] Variable and function names should not be longer than 10 characters. # 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\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match CamelCase. lint( text = \"xYz <- 1L\", linters = object_name_linter(styles = c(\"UPPERCASE\", \"lowercase\")) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match UPPERCASE or lowercase. lint( text = \"MyVar <- 1L\", linters = object_name_linter(styles = \"dotted.case\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match dotted.case. lint( text = \"asd <- 1L\", linters = object_name_linter(regexes = c(my_style = \"F$\", \"f$\")) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match my_style or /f$/. # 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() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols. 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\") ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[object_overwrite_linter] 'lint' is an exported object from package 'lintr'. Avoid re-using such symbols. # 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() ) #> ::warning file=,line=1,col=21::file=,line=1,col=21,[object_usage_linter] local variable 'x' assigned but may not be used # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[one_call_pipe_linter] Avoid pipe %>% for expressions with only a single call. lint( text = \"DT %>% .[grp == 'a', sum(v)]\", linters = one_call_pipe_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[one_call_pipe_linter] Avoid pipe %>% for expressions with only a single call. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = \"any(!x)\", linters = outer_negation_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. # 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() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[package_hooks_linter] .onLoad() should take two arguments, with the first starting with 'lib' and the second starting with 'pkg'. lint( text = \".onAttach <- function(lib, pkg) { require(foo) }\", linters = package_hooks_linter() ) #> ::warning file=,line=1,col=35::file=,line=1,col=35,[package_hooks_linter] Don't alter the search() path in .onAttach() by calling require(). lint( text = \".onDetach <- function(pkg) { }\", linters = package_hooks_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[package_hooks_linter] .onDetach() should take one argument starting with 'lib'. # 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() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[paren_body_linter] Put a space between a right parenthesis and a body expression. # 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() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] paste0(...) is better than paste(..., sep = \"\"). lint( text = 'paste(c(\"a\", \"b\"), collapse = \", \")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] toString(.) is more expressive than paste(., collapse = \", \"). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists lint( text = 'paste0(c(\"a\", \"b\"), sep = \" \")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] sep= is not a formal argument to paste0(); did you mean to use paste(), or collapse=? lint( text = 'paste0(rep(\"*\", 10L), collapse = \"\")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] strrep(x, times) is better than paste0(rep(x, times), collapse = \"\"). #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used. lint( text = 'paste0(\"http://site.com/\", path)', linters = paste_linter(allow_file_path = \"never\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[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. lint( text = 'paste0(x, collapse = \"\")', linters = paste_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used. # 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() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`. #> ::warning file=,line=1,col=18::file=,line=1,col=18,[pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`. # 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() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>. lint( text = \"1:3 %>% mean() %>% as.character()\", linters = pipe_consistency_linter(\"|>\") ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator. #> ::warning file=,line=1,col=16::file=,line=1,col=16,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator. # 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() ) #> ::warning file=,line=2,col=9::file=,line=2,col=9,[pipe_continuation_linter] Put a space before `%>%` and a new line after it, unless the full pipeline fits on one line. code_lines <- \"1:3 |> mean() |>\\n as.character()\" writeLines(code_lines) #> 1:3 |> mean() |> #> as.character() lint( text = code_lines, linters = pipe_continuation_linter() ) #> ::warning file=,line=1,col=15::file=,line=1,col=15,[pipe_continuation_linter] Put a space before `|>` and a new line after it, unless the full pipeline fits on one line. # okay lint( text = \"1:3 %>% mean() %>% as.character()\", linters = pipe_continuation_linter() ) code_lines <- \"1:3 %>%\\n mean() %>%\\n as.character()\" writeLines(code_lines) #> 1:3 %>% #> mean() %>% #> as.character() lint( text = code_lines, linters = pipe_continuation_linter() ) lint( text = \"1:3 |> mean() |> as.character()\", linters = pipe_continuation_linter() ) code_lines <- \"1:3 |>\\n mean() |>\\n as.character()\" writeLines(code_lines) #> 1:3 |> #> mean() |> #> as.character() lint( text = code_lines, linters = pipe_continuation_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of return() in magrittr pipelines — pipe_return_linter","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"return() inside magrittr pipeline actually execute return() like expect: \\(x) { x %>% return(); FALSE } return FALSE! technically work \"expected\" final statement function body, usage misleading. Instead, assign pipe outcome variable return .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"","code":"pipe_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"best_practices, common_mistakes","code":""},{"path":"https://lintr.r-lib.org/dev/reference/pipe_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of return() in magrittr pipelines — pipe_return_linter","text":"","code":"# will produce lints lint( text = \"function(x) x %>% return()\", linters = pipe_return_linter() ) #> ::warning file=,line=1,col=19::file=,line=1,col=19,[pipe_return_linter] Avoid return() as the final step of a magrittr pipeline. Instead, assign the output of the pipeline to a well-named object and return that. # okay code <- \"function(x) {\\n y <- sum(x)\\n return(y)\\n}\" writeLines(code) #> function(x) { #> y <- sum(x) #> return(y) #> } lint( text = code, linters = pipe_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/pkg_testthat_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Testthat linters — pkg_testthat_linters","title":"Testthat linters — pkg_testthat_linters","text":"Linters encouraging best practices within testthat suites.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/pkg_testthat_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Testthat linters — pkg_testthat_linters","text":"following linters tagged 'pkg_testthat': 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 yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of print() for logging — print_linter","title":"Block usage of print() for logging — print_linter","text":"default print method character vectors appropriate interactively inspecting objects, logging messages. Thus checked-usage like print(paste('Data ', nrow(DF), 'rows.')) better served using cat(), e.g. cat(sprintf('Data %d rows.\\n', nrow(DF))) (noting using cat() entails supplying line returns, glue::glue() might preferable sprintf() constructing templated strings). Lastly, note message() differs slightly cat() prints stderr default, stdout, still good option consider logging purposes.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of print() for logging — print_linter","text":"","code":"print_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of print() for logging — print_linter","text":"best_practices, consistency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/print_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of print() for logging — print_linter","text":"","code":"# will produce lints lint( text = \"print('a')\", linters = print_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[print_linter] Use cat() instead of print() logging messages. Use message() in cases calling for a signalled condition. lint( text = \"print(paste(x, 'y'))\", linters = print_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[print_linter] Use cat() instead of print() logging messages. Use message() in cases calling for a signalled condition. # okay lint( text = \"print(x)\", linters = print_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Character string quote linter — quotes_linter","title":"Character string quote linter — quotes_linter","text":"Check desired quote delimiter used string constants.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Character string quote linter — quotes_linter","text":"","code":"quotes_linter(delimiter = c(\"\\\"\", \"'\"))"},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Character string quote linter — quotes_linter","text":"delimiter quote delimiter accept. Defaults tidyverse default \" (double-quoted strings).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Character string quote linter — quotes_linter","text":"configurable, consistency, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/quotes_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Character string quote linter — quotes_linter","text":"","code":"# will produce lints lint( text = \"c('a', 'b')\", linters = quotes_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[quotes_linter] Only use double-quotes. #> ::warning file=,line=1,col=8::file=,line=1,col=8,[quotes_linter] Only use double-quotes. # okay lint( text = 'c(\"a\", \"b\")', linters = quotes_linter() ) code_lines <- \"paste0(x, '\\\"this is fine\\\"')\" writeLines(code_lines) #> paste0(x, '\"this is fine\"') lint( text = code_lines, linters = quotes_linter() ) # okay lint( text = \"c('a', 'b')\", linters = quotes_linter(delimiter = \"'\") )"},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":null,"dir":"Reference","previous_headings":"","what":"Read lintr settings — read_settings","title":"Read lintr settings — read_settings","text":"Lintr searches settings given source file following order: options defined linter.setting. linter_file directory linter_file project directory linter_file user home directory default_settings()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Read lintr settings — read_settings","text":"","code":"read_settings(filename)"},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Read lintr settings — read_settings","text":"filename Source file linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/read_settings.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Read lintr settings — read_settings","text":"default linter_file name .lintr can changed option lintr.linter_file environment variable R_LINTR_LINTER_FILE file DCF file, see base::read.dcf() details. example .lintr file: Experimentally, also support keeping config plain R file. default look file named .lintr.R (directories search .lintr). still deciding future config support lintr, user feedback welcome. advantage R maps closely configs actually stored, whereas DCF approach requires somewhat awkward formatting parseable R code within valid DCF key-value pairs. main disadvantage R file might flexible, users tempted write configs side effects causing hard--detect bugs like YAML work, require new dependencies harder parse programmatically visually. example .lintr.R file:","code":"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\" )"},{"path":"https://lintr.r-lib.org/dev/reference/readability_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Readability linters — readability_linters","title":"Readability linters — readability_linters","text":"Linters highlighting readability issues, missing whitespace.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/readability_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Readability linters — readability_linters","text":"following linters tagged 'readability': boolean_arithmetic_linter brace_linter commas_linter commented_code_linter comparison_negation_linter conjunct_test_linter consecutive_assertion_linter consecutive_mutate_linter cyclocomp_linter empty_assignment_linter expect_length_linter expect_named_linter expect_not_linter expect_true_false_linter fixed_regex_linter for_loop_index_linter function_left_parentheses_linter function_return_linter if_not_else_linter if_switch_linter implicit_assignment_linter indentation_linter infix_spaces_linter inner_combine_linter is_numeric_linter keyword_quote_linter length_levels_linter lengths_linter library_call_linter line_length_linter matrix_apply_linter nested_ifelse_linter nested_pipe_linter numeric_leading_zero_linter object_length_linter object_overwrite_linter object_usage_linter one_call_pipe_linter outer_negation_linter paren_body_linter pipe_call_linter pipe_consistency_linter pipe_continuation_linter quotes_linter redundant_equals_linter rep_len_linter repeat_linter sample_int_linter scalar_in_linter semicolon_linter sort_linter spaces_inside_linter spaces_left_parentheses_linter stopifnot_all_linter string_boundary_linter system_file_linter T_and_F_symbol_linter unnecessary_concatenation_linter unnecessary_lambda_linter unnecessary_nesting_linter unnecessary_placeholder_linter unreachable_code_linter which_grepl_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of ==, != on logical vectors — redundant_equals_linter","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"Testing x == TRUE redundant x logical vector. Wherever used improve readability, solution instead improve naming object better indicate contents logical. can done using prefixes (, , can, etc.). example, is_child, has_parent_supervision, can_watch_horror_movie clarify logical nature, child, parent_supervision, watch_horror_movie .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"","code":"redundant_equals_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"best_practices, common_mistakes, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of ==, != on logical vectors — redundant_equals_linter","text":"","code":"# will produce lints lint( text = \"if (any(x == TRUE)) 1\", linters = redundant_equals_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[redundant_equals_linter] Using == on a logical vector is redundant. Well-named logical vectors can be used directly in filtering. For data.table's `i` argument, wrap the column name in (), like `DT[(is_treatment)]`. lint( text = \"if (any(x != FALSE)) 0\", linters = redundant_equals_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[redundant_equals_linter] Using != on a logical vector is redundant. Well-named logical vectors can be used directly in filtering. For data.table's `i` argument, wrap the column name in (), like `DT[(is_treatment)]`. # okay lint( text = \"if (any(x)) 1\", linters = redundant_equals_linter() ) lint( text = \"if (!all(x)) 0\", linters = redundant_equals_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"Expressions like ifelse(x, TRUE, FALSE) ifelse(x, FALSE, TRUE) redundant; just x !x suffice R code logical vectors core data structure. ifelse(x, 1, 0) also .numeric(x), even needed rarely.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"","code":"redundant_ifelse_linter(allow10 = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"allow10 Logical, default FALSE. TRUE, usage like ifelse(x, 1, 0) allowed, .e., usage like ifelse(x, TRUE, FALSE) linted.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"best_practices, configurable, consistency, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/redundant_ifelse_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Prevent ifelse() from being used to produce TRUE/FALSE or 1/0 — redundant_ifelse_linter","text":"","code":"# will produce lints lint( text = \"ifelse(x >= 2.5, TRUE, FALSE)\", linters = redundant_ifelse_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[redundant_ifelse_linter] Just use the logical condition (or its negation) directly instead of calling ifelse(x, TRUE, FALSE) lint( text = \"ifelse(x < 2.5, 1L, 0L)\", linters = redundant_ifelse_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[redundant_ifelse_linter] Prefer as.integer(x) to ifelse(x, 1L, 0L) if really needed. # okay lint( text = \"x >= 2.5\", linters = redundant_ifelse_linter() ) # Note that this is just to show the strict equivalent of the example above; # converting to integer is often unnecessary and the logical vector itself # should suffice. lint( text = \"as.integer(x < 2.5)\", linters = redundant_ifelse_linter() ) lint( text = \"ifelse(x < 2.5, 1L, 0L)\", linters = redundant_ifelse_linter(allow10 = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/regex_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Regular expression linters — regex_linters","title":"Regular expression linters — regex_linters","text":"Linters examine usage regular expressions functions executing user code.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/regex_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Regular expression linters — regex_linters","text":"following linters tagged 'regex': fixed_regex_linter regex_subset_linter string_boundary_linter which_grepl_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"Using value = TRUE grep() returns subset input matches pattern, e.g. grep(\"[-m]\", letters, value = TRUE) return first 13 elements (m).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"","code":"regex_subset_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"letters[grep(\"[-m]\", letters)] letters[grepl(\"[-m]\", letters)] return thing, circuitously verbosely. stringr package also provides even readable alternative, namely str_subset(), preferred versions using str_detect() str_which().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"Note x[grep(pattern, x)] grep(pattern, x, value = TRUE) completely interchangeable x character (commonly, x factor), output latter character vector former remains factor. still may preferable refactor code, may faster match pattern levels(x) use subset instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"best_practices, efficiency, regex","code":""},{"path":"https://lintr.r-lib.org/dev/reference/regex_subset_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of direct methods for subsetting strings via regex — regex_subset_linter","text":"","code":"# will produce lints lint( text = \"x[grep(pattern, x)]\", linters = regex_subset_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[regex_subset_linter] Prefer grep(pattern, x, ..., value = TRUE) over x[grep(pattern, x, ...)] and x[grepl(pattern, x, ...)]. lint( text = \"x[stringr::str_which(x, pattern)]\", linters = regex_subset_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[regex_subset_linter] Prefer stringr::str_subset(x, pattern) over x[str_detect(x, pattern)] and x[str_which(x, pattern)]. # okay lint( text = \"grep(pattern, x, value = TRUE)\", linters = regex_subset_linter() ) lint( text = \"stringr::str_subset(x, pattern)\", linters = regex_subset_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"rep(x, length.= n) calls rep_len(x, n) \"hood\". latter thus direct equally readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"","code":"rep_len_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/rep_len_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of rep_len(x, n) over rep(x, length.out = n) — rep_len_linter","text":"","code":"# will produce lints lint( text = \"rep(1:3, length.out = 10)\", linters = rep_len_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[rep_len_linter] Use rep_len(x, n) instead of rep(x, length.out = n). # okay lint( text = \"rep_len(1:3, 10)\", linters = rep_len_linter() ) lint( text = \"rep(1:3, each = 2L, length.out = 10L)\", linters = rep_len_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Repeat linter — repeat_linter","title":"Repeat linter — repeat_linter","text":"Check (TRUE) used infinite loops.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Repeat linter — repeat_linter","text":"","code":"repeat_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Repeat linter — repeat_linter","text":"readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/repeat_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Repeat linter — repeat_linter","text":"","code":"# will produce lints lint( text = \"while (TRUE) { }\", linters = repeat_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[repeat_linter] Use 'repeat' instead of 'while (TRUE)' for infinite loops. # okay lint( text = \"repeat { }\", linters = repeat_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Return linter — return_linter","title":"Return linter — return_linter","text":"linter checks functions' return() expressions.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return linter — return_linter","text":"","code":"return_linter( return_style = c(\"implicit\", \"explicit\"), allow_implicit_else = TRUE, return_functions = NULL, except = NULL, except_regex = NULL )"},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return linter — return_linter","text":"return_style Character string naming return style. \"implicit\", default, enforces Tidyverse guide recommendation leave terminal returns implicit. \"explicit\" style requires return() always explicitly supplied. allow_implicit_else Logical, default TRUE. FALSE, functions terminal clause must always else clause, making NULL alternative explicit necessary. Similarly, functions terminal switch() statements must explicit default case. return_functions Character vector functions accepted terminal calls return_style = \"explicit\". addition exit functions base always allowed: stop(), q(), quit(), invokeRestart(), tryInvokeRestart(), UseMethod(), NextMethod(), standardGeneric(), callNextMethod(), .C(), .Call(), .External(), .Fortran(). except, except_regex Character vector functions checked return_style = \"explicit\". addition namespace hook functions never checked: .onLoad(), .onUnload(), .onAttach(), .onDetach(), .Last.lib(), .First() .Last(). except matches function names exactly, except_regex exclusion pattern matching rex::re_matches().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Return linter — return_linter","text":"configurable, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return linter — return_linter","text":"","code":"# will produce lints code <- \"function(x) {\\n return(x + 1)\\n}\" writeLines(code) #> function(x) { #> return(x + 1) #> } lint( text = code, linters = return_linter() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[return_linter] Use implicit return behavior; explicit return() is not needed. code <- \"function(x) {\\n x + 1\\n}\" writeLines(code) #> function(x) { #> x + 1 #> } lint( text = code, linters = return_linter(return_style = \"explicit\") ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[return_linter] All functions must have an explicit return(). code <- \"function(x) {\\n if (x > 0) 2\\n}\" writeLines(code) #> function(x) { #> if (x > 0) 2 #> } lint( text = code, linters = return_linter(allow_implicit_else = FALSE) ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[return_linter] All functions with terminal if statements must have a corresponding terminal else clause. # okay code <- \"function(x) {\\n x + 1\\n}\" writeLines(code) #> function(x) { #> x + 1 #> } lint( text = code, linters = return_linter() ) code <- \"function(x) {\\n return(x + 1)\\n}\" writeLines(code) #> function(x) { #> return(x + 1) #> } lint( text = code, linters = return_linter(return_style = \"explicit\") ) code <- \"function(x) {\\n if (x > 0) 2 else NULL\\n}\" writeLines(code) #> function(x) { #> if (x > 0) 2 else NULL #> } lint( text = code, linters = return_linter(allow_implicit_else = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/robustness_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Robustness linters — robustness_linters","title":"Robustness linters — robustness_linters","text":"Linters highlighting code robustness issues, possibly wrong edge case behavior.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/robustness_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Robustness linters — robustness_linters","text":"following linters tagged 'robustness': absolute_path_linter backport_linter class_equals_linter equals_na_linter for_loop_index_linter missing_package_linter namespace_linter nonportable_path_linter object_overwrite_linter routine_registration_linter sample_int_linter seq_linter strings_as_factors_linter T_and_F_symbol_linter terminal_close_linter undesirable_function_linter undesirable_operator_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Identify unregistered native routines — routine_registration_linter","title":"Identify unregistered native routines — routine_registration_linter","text":"preferable register routines efficiency safety.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Identify unregistered native routines — routine_registration_linter","text":"","code":"routine_registration_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Identify unregistered native routines — routine_registration_linter","text":"best_practices, efficiency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/routine_registration_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Identify unregistered native routines — routine_registration_linter","text":"","code":"# will produce lints lint( text = '.Call(\"cpp_routine\", PACKAGE = \"mypkg\")', linters = routine_registration_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[routine_registration_linter] Register your native code routines with useDynLib and R_registerRoutines(). lint( text = '.Fortran(\"f_routine\", PACKAGE = \"mypkg\")', linters = routine_registration_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[routine_registration_linter] Register your native code routines with useDynLib and R_registerRoutines(). # okay lint( text = \".Call(cpp_routine)\", linters = routine_registration_linter() ) lint( text = \".Fortran(f_routine)\", linters = routine_registration_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"sample.int() preferable sample() case sampling numbers 1 n. sample calls sample.int() \"hood\".","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"","code":"sample_int_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"efficiency, readability, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sample_int_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of sample.int(n, m, ...) over sample(1:n, m, ...) — sample_int_linter","text":"","code":"# will produce lints lint( text = \"sample(1:10, 2)\", linters = sample_int_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...). lint( text = \"sample(seq(4), 2)\", linters = sample_int_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(seq(n), m, ...). lint( text = \"sample(seq_len(8), 2)\", linters = sample_int_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(seq_len(n), m, ...). # okay lint( text = \"sample(seq(1, 5, by = 2), 2)\", linters = sample_int_linter() ) lint( text = \"sample(letters, 2)\", linters = sample_int_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sarif_output.html","id":null,"dir":"Reference","previous_headings":"","what":"SARIF Report for lint results — sarif_output","title":"SARIF Report for lint results — sarif_output","text":"Generate report linting results using SARIF format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sarif_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"SARIF Report for lint results — sarif_output","text":"","code":"sarif_output(lints, filename = \"lintr_results.sarif\")"},{"path":"https://lintr.r-lib.org/dev/reference/sarif_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"SARIF Report for lint results — sarif_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage like x %in% ","title":"Block usage like x %in% ","text":"vector %% set appropriate matching vector set, set size 1, == appropriate.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage like x %in% ","text":"","code":"scalar_in_linter(in_operators = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block usage like x %in% ","text":"in_operators Character vector additional infix operators behave like %% operator, e.g. {data.table}'s %chin% operator.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage like x %in% ","text":"scalar %% vector OK, alternative ((vector == scalar)) circuitous & potentially less clear.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage like x %in% ","text":"best_practices, configurable, consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/scalar_in_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage like x %in% ","text":"","code":"# will produce lints lint( text = \"x %in% 1L\", linters = scalar_in_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[scalar_in_linter] Use comparison operators (e.g. ==, !=, etc.) to match length-1 scalars instead of %in%. Note that comparison operators preserve NA where %in% does not. lint( text = \"x %chin% 'a'\", linters = scalar_in_linter(in_operators = \"%chin%\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[scalar_in_linter] Use comparison operators (e.g. ==, !=, etc.) to match length-1 scalars instead of %chin%. Note that comparison operators preserve NA where %chin% does not. # okay lint( text = \"x %in% 1:10\", linters = scalar_in_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Semicolon linter — semicolon_linter","title":"Semicolon linter — semicolon_linter","text":"Check semicolons terminate expressions.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Semicolon linter — semicolon_linter","text":"","code":"semicolon_linter(allow_compound = FALSE, allow_trailing = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Semicolon linter — semicolon_linter","text":"allow_compound Logical, default FALSE. TRUE, \"compound\" semicolons (e.g. x; y, .e., line code) allowed. allow_trailing Logical, default FALSE. TRUE, \"trailing\" semicolons (.e., terminate lines code) allowed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Semicolon linter — semicolon_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/semicolon_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Semicolon linter — semicolon_linter","text":"","code":"# will produce lints lint( text = \"a <- 1;\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[semicolon_linter] Remove trailing semicolons. lint( text = \"a <- 1; b <- 1\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[semicolon_linter] Replace compound semicolons by a newline. lint( text = \"function() { a <- 1; b <- 1 }\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=20::file=,line=1,col=20,[semicolon_linter] Replace compound semicolons by a newline. # okay lint( text = \"a <- 1\", linters = semicolon_linter() ) lint( text = \"a <- 1;\", linters = semicolon_linter(allow_trailing = TRUE) ) code_lines <- \"a <- 1\\nb <- 1\" writeLines(code_lines) #> a <- 1 #> b <- 1 lint( text = code_lines, linters = semicolon_linter() ) lint( text = \"a <- 1; b <- 1\", linters = semicolon_linter(allow_compound = TRUE) ) code_lines <- \"function() { \\n a <- 1\\n b <- 1\\n}\" writeLines(code_lines) #> function() { #> a <- 1 #> b <- 1 #> } lint( text = code_lines, linters = semicolon_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Sequence linter — seq_linter","title":"Sequence linter — seq_linter","text":"linter checks 1:length(...), 1:nrow(...), 1:ncol(...), 1:NROW(...) 1:NCOL(...) expressions base-R, usage conjunction seq() (e.g., seq(length(...)), seq(nrow(...)), etc.).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sequence linter — seq_linter","text":"","code":"seq_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Sequence linter — seq_linter","text":"Additionally, checks 1:n() ({dplyr}) 1:.N ({data.table}). often cause bugs right-hand side zero. safer use base::seq_len() base::seq_along() instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Sequence linter — seq_linter","text":"best_practices, consistency, default, efficiency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/seq_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Sequence linter — seq_linter","text":"","code":"# will produce lints lint( text = \"seq(length(x))\", linters = seq_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[seq_linter] Use seq_along(...) instead of seq(length(...)), which is likely to be wrong in the empty edge case. lint( text = \"1:nrow(x)\", linters = seq_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[seq_linter] Use seq_len(nrow(...)) instead of 1:nrow(...), which is likely to be wrong in the empty edge case. lint( text = \"dplyr::mutate(x, .id = 1:n())\", linters = seq_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[seq_linter] Use seq_len(n()) instead of 1:n(), which is likely to be wrong in the empty edge case. # okay lint( text = \"seq_along(x)\", linters = seq_linter() ) lint( text = \"seq_len(nrow(x))\", linters = seq_linter() ) lint( text = \"dplyr::mutate(x, .id = seq_len(n()))\", linters = seq_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check for common mistakes around sorting vectors — sort_linter","title":"Check for common mistakes around sorting vectors — sort_linter","text":"linter checks common mistakes using order() sort().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check for common mistakes around sorting vectors — sort_linter","text":"","code":"sort_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Check for common mistakes around sorting vectors — sort_linter","text":"First, requires usage sort() .[order(.)]. sort() dedicated option sort list vector. legible around twice fast .[order(.)], gap performance growing vector size. Second, requires usage .unsorted() equivalents using sort(). base function .unsorted() exists test sortedness vector. Prefer inefficient less-readable equivalents like x != sort(x). goes checking x == sort(x) -- use !.unsorted(x) instead. Moreover, use x == sort(x) can risky sort() drops missing elements default, meaning == might end trying compare vectors differing lengths.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check for common mistakes around sorting vectors — sort_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check for common mistakes around sorting vectors — sort_linter","text":"","code":"# will produce lints lint( text = \"x[order(x)]\", linters = sort_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[sort_linter] sort(x, na.last = TRUE) is better than x[order(x)]. Note that it's always preferable to save the output of order() for the same variable as a local variable than to re-compute it. lint( text = \"x[order(x, decreasing = TRUE)]\", linters = sort_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[sort_linter] sort(x, decreasing = TRUE, na.last = TRUE) is better than x[order(x, decreasing = TRUE)]. Note that it's always preferable to save the output of order() for the same variable as a local variable than to re-compute it. lint( text = \"sort(x) == x\", linters = sort_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sort_linter] Use !is.unsorted(x) to test the sortedness of a vector. # okay lint( text = \"x[sample(order(x))]\", linters = sort_linter() ) lint( text = \"y[order(x)]\", linters = sort_linter() ) lint( text = \"sort(x, decreasing = TRUE) == x\", linters = sort_linter() ) # If you are sorting several objects based on the order of one of them, such # as: x <- sample(1:26) y <- letters newx <- x[order(x)] newy <- y[order(x)] # This will be flagged by the linter. However, in this very specific case, # it would be clearer and more efficient to run order() once and assign it # to an object, rather than mix and match order() and sort() index <- order(x) newx <- x[index] newy <- y[index]"},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Spaces inside linter — spaces_inside_linter","title":"Spaces inside linter — spaces_inside_linter","text":"Check parentheses square brackets spaces directly inside , .e., directly following opening delimiter directly preceding closing delimiter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spaces inside linter — spaces_inside_linter","text":"","code":"spaces_inside_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Spaces inside linter — spaces_inside_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_inside_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spaces inside linter — spaces_inside_linter","text":"","code":"# will produce lints lint( text = \"c( TRUE, FALSE )\", linters = spaces_inside_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[spaces_inside_linter] Do not place spaces after parentheses. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[spaces_inside_linter] Do not place spaces before parentheses. lint( text = \"x[ 1L ]\", linters = spaces_inside_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[spaces_inside_linter] Do not place spaces after square brackets. #> ::warning file=,line=1,col=6::file=,line=1,col=6,[spaces_inside_linter] Do not place spaces before square brackets. # okay lint( text = \"c(TRUE, FALSE)\", linters = spaces_inside_linter() ) lint( text = \"x[1L]\", linters = spaces_inside_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Spaces before parentheses linter — spaces_left_parentheses_linter","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"Check left parentheses space unless function call.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"","code":"spaces_left_parentheses_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/spaces_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Spaces before parentheses linter — spaces_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"if(TRUE) x else y\", linters = spaces_left_parentheses_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call. # okay lint( text = \"if (TRUE) x else y\", linters = spaces_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require correct sprintf() calls — sprintf_linter","title":"Require correct sprintf() calls — sprintf_linter","text":"Check inconsistent number arguments arguments incompatible types (literal arguments) sprintf() calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require correct sprintf() calls — sprintf_linter","text":"","code":"sprintf_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require correct sprintf() calls — sprintf_linter","text":"gettextf() calls also included, since gettextf() thin wrapper around sprintf().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require correct sprintf() calls — sprintf_linter","text":"common_mistakes, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sprintf_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require correct sprintf() calls — sprintf_linter","text":"","code":"# will produce lints lint( text = 'sprintf(\"hello %s %s %d\", x, y)', linters = sprintf_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[sprintf_linter] too few arguments # okay lint( text = 'sprintf(\"hello %s %s %d\", x, y, z)', linters = sprintf_linter() ) lint( text = 'sprintf(\"hello %s %s %d\", x, y, ...)', linters = sprintf_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of all() within stopifnot() — stopifnot_all_linter","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"stopifnot() actually checks () \"hood\" vector, produces better error message stopifnot(()) .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"","code":"stopifnot_all_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/stopifnot_all_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of all() within stopifnot() — stopifnot_all_linter","text":"","code":"# will produce lints lint( text = \"stopifnot(all(x > 0))\", linters = stopifnot_all_linter() ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[stopifnot_all_linter] Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under the hood' and provides a better error message in case of failure. lint( text = \"stopifnot(y > 3, all(x < 0))\", linters = stopifnot_all_linter() ) #> ::warning file=,line=1,col=18::file=,line=1,col=18,[stopifnot_all_linter] Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under the hood' and provides a better error message in case of failure. # okay lint( text = \"stopifnot(is.null(x) || all(x > 0))\", linters = stopifnot_all_linter() ) lint( text = \"assert_that(all(x > 0))\", linters = stopifnot_all_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"startsWith() used detect fixed initial substrings; readable efficient equivalents using grepl() substr(). c.f. startsWith(x, \"abc\"), grepl(\"^abc\", x), substr(x, 1L, 3L) == \"abc\".","code":""},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"","code":"string_boundary_linter(allow_grepl = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"allow_grepl Logical, default FALSE. TRUE, usages grepl() ignored. authors may prefer conciseness offered grepl() whereby NA input maps FALSE output, direct equivalent startsWith() endsWith().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"Ditto using endsWith() detect fixed terminal substrings. Note difference behavior grepl() startsWith() (endsWith()) handle missing values. particular, grepl(), NA inputs considered FALSE, startsWith(), NA inputs NA outputs. means strict equivalent grepl(\"^abc\", x) !.na(x) & startsWith(x, \"abc\"). lint grepl() usages default !.na() version explicit respect NA handling -- though documented, way grepl() handles missing inputs may surprising users.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"configurable, efficiency, readability, regex","code":""},{"path":"https://lintr.r-lib.org/dev/reference/string_boundary_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of startsWith() and endsWith() over grepl()/substr() versions — string_boundary_linter","text":"","code":"# will produce lints lint( text = 'grepl(\"^a\", x)', linters = string_boundary_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[string_boundary_linter] Use !is.na(x) & startsWith(x, string) to detect a fixed initial substring, or, if missingness is not a concern, just startsWith(). Doing so is more readable and more efficient. lint( text = 'grepl(\"z$\", x)', linters = string_boundary_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[string_boundary_linter] Use !is.na(x) & endsWith(x, string) to detect a fixed terminal substring, or, if missingness is not a concern, just endsWith(). Doing so is more readable and more efficient. # okay lint( text = 'startsWith(x, \"a\")', linters = string_boundary_linter() ) lint( text = 'endsWith(x, \"z\")', linters = string_boundary_linter() ) # If missing values are present, the suggested alternative wouldn't be strictly # equivalent, so this linter can also be turned off in such cases. lint( text = 'grepl(\"z$\", x)', linters = string_boundary_linter(allow_grepl = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"Designed code bases written versions R 4.0 seeking upgrade R >= 4.0, one biggest pain points surely flipping default value stringsAsFactors TRUE FALSE.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"","code":"strings_as_factors_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"always possible tell statically whether change break existing code R dynamically typed -- e.g. data.frame(x) x string, code affected, x number, code unaffected. However, data.frame(x = \"\"), output unambiguously affected. can instead supply stringsAsFactors = TRUE, make code backwards-compatible. See https://developer.r-project.org/Blog/public/2020/02/16/stringsasfactors/.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/strings_as_factors_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Identify cases where stringsAsFactors should be supplied explicitly — strings_as_factors_linter","text":"","code":"# will produce lints lint( text = 'data.frame(x = \"a\")', linters = strings_as_factors_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[strings_as_factors_linter] Supply an explicit value for stringsAsFactors for this code to work before and after R version 4.0. # okay lint( text = 'data.frame(x = \"a\", stringsAsFactors = TRUE)', linters = strings_as_factors_linter() ) lint( text = 'data.frame(x = \"a\", stringsAsFactors = FALSE)', linters = strings_as_factors_linter() ) lint( text = \"data.frame(x = 1.2)\", linters = strings_as_factors_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/style_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Style linters — style_linters","title":"Style linters — style_linters","text":"Linters highlighting code style issues.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/style_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Style linters — style_linters","text":"following linters tagged 'style': assignment_linter brace_linter commas_linter commented_code_linter condition_call_linter consecutive_assertion_linter cyclocomp_linter function_argument_linter function_left_parentheses_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter keyword_quote_linter library_call_linter line_length_linter numeric_leading_zero_linter object_length_linter object_name_linter object_usage_linter one_call_pipe_linter package_hooks_linter paren_body_linter pipe_call_linter pipe_consistency_linter pipe_continuation_linter quotes_linter repeat_linter return_linter semicolon_linter spaces_inside_linter spaces_left_parentheses_linter T_and_F_symbol_linter todo_comment_linter trailing_blank_lines_linter trailing_whitespace_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of file.path() with system.file() — system_file_linter","title":"Block usage of file.path() with system.file() — system_file_linter","text":"system.file() ... argument , internally, passed file.path(), including user code repetitive.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of file.path() with system.file() — system_file_linter","text":"","code":"system_file_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of file.path() with system.file() — system_file_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/system_file_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of file.path() with system.file() — system_file_linter","text":"","code":"# will produce lints lint( text = 'system.file(file.path(\"path\", \"to\", \"data\"), package = \"foo\")', linters = system_file_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[system_file_linter] Use the `...` argument of system.file() to expand paths, e.g. system.file(\"data\", \"model.csv\", package = \"myrf\") instead of system.file(file.path(\"data\", \"model.csv\"), package = \"myrf\") lint( text = 'file.path(system.file(package = \"foo\"), \"path\", \"to\", \"data\")', linters = system_file_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[system_file_linter] Use the `...` argument of system.file() to expand paths, e.g. system.file(\"data\", \"model.csv\", package = \"myrf\") instead of file.path(system.file(package = \"myrf\"), \"data\", \"model.csv\") # okay lint( text = 'system.file(\"path\", \"to\", \"data\", package = \"foo\")', linters = system_file_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Prohibit close() from terminating a function definition — terminal_close_linter","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"Functions end close(x) almost always better written using .exit(close(x)) close x defined /opened.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"","code":"terminal_close_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"best_practices, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/terminal_close_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Prohibit close() from terminating a function definition — terminal_close_linter","text":"","code":"# will produce lints code <- paste( \"f <- function(fl) {\", \" conn <- file(fl, open = 'r')\", \" readLines(conn)\", \" close(conn)\", \"}\", sep = \"\\n\" ) writeLines(code) #> f <- function(fl) { #> conn <- file(fl, open = 'r') #> readLines(conn) #> close(conn) #> } lint( text = code, linters = terminal_close_linter() ) #> ::warning file=,line=4,col=3::file=,line=4,col=3,[terminal_close_linter] Use on.exit(close(x)) to close connections instead of running it as the last call in a function. # okay code <- paste( \"f <- function(fl) {\", \" conn <- file(fl, open = 'r')\", \" on.exit(close(conn))\", \" readLines(conn)\", \"}\", sep = \"\\n\" ) writeLines(code) #> f <- function(fl) { #> conn <- file(fl, open = 'r') #> on.exit(close(conn)) #> readLines(conn) #> } lint( text = code, linters = terminal_close_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/tidy_design_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidyverse design linters — tidy_design_linters","title":"Tidyverse design linters — tidy_design_linters","text":"Linters based guidelines described 'Tidy design principles' book.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/tidy_design_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Tidyverse design linters — tidy_design_linters","text":"following linters tagged 'tidy_design': condition_call_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"TODO comment linter — todo_comment_linter","title":"TODO comment linter — todo_comment_linter","text":"Check source contains TODO comments (case-insensitive).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"TODO comment linter — todo_comment_linter","text":"","code":"todo_comment_linter(todo = c(\"todo\", \"fixme\"), except_regex = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"TODO comment linter — todo_comment_linter","text":"todo Vector case-insensitive strings identify TODO comments. except_regex Vector case-sensitive regular expressions identify valid TODO comments.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"TODO comment linter — todo_comment_linter","text":"configurable, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/todo_comment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"TODO comment linter — todo_comment_linter","text":"","code":"# will produce lints lint( text = \"x + y # TOODOO\", linters = todo_comment_linter(todo = \"toodoo\") ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[todo_comment_linter] Remove TODO comments. lint( text = \"pi <- 1.0 # FIIXMEE\", linters = todo_comment_linter(todo = \"fiixmee\") ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[todo_comment_linter] Remove TODO comments. lint( text = \"x <- TRUE # TOODOO(#1234): Fix this hack.\", linters = todo_comment_linter() ) # okay lint( text = \"x + y # my informative comment\", linters = todo_comment_linter() ) lint( text = \"pi <- 3.14\", linters = todo_comment_linter() ) lint( text = \"x <- TRUE\", linters = todo_comment_linter() ) lint( text = \"x <- TRUE # TODO(#1234): Fix this hack.\", linters = todo_comment_linter(except_regex = \"TODO\\\\(#[0-9]+\\\\):\") )"},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Trailing blank lines linter — trailing_blank_lines_linter","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"Check trailing blank lines source code.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"","code":"trailing_blank_lines_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_blank_lines_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Trailing blank lines linter — trailing_blank_lines_linter","text":"","code":"# will produce lints f <- tempfile() cat(\"x <- 1\\n\\n\", file = f) writeLines(readChar(f, file.size(f))) #> x <- 1 #> #> lint( filename = f, linters = trailing_blank_lines_linter() ) #> ::warning file=/tmp/RtmpgA7L92/file17c14a8324c6,line=2,col=1::file=/tmp/RtmpgA7L92/file17c14a8324c6,line=2,col=1,[trailing_blank_lines_linter] Remove trailing blank lines. unlink(f) # okay cat(\"x <- 1\\n\", file = f) writeLines(readChar(f, file.size(f))) #> x <- 1 #> lint( filename = f, linters = trailing_blank_lines_linter() ) unlink(f)"},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Trailing whitespace linter — trailing_whitespace_linter","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"Check space characters end source lines.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"","code":"trailing_whitespace_linter(allow_empty_lines = FALSE, allow_in_strings = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"allow_empty_lines Suppress lints lines contain whitespace. allow_in_strings Suppress lints trailing whitespace string constants.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"configurable, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/trailing_whitespace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Trailing whitespace linter — trailing_whitespace_linter","text":"","code":"# will produce lints lint( text = \"x <- 1.2 \", linters = trailing_whitespace_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[trailing_whitespace_linter] Remove trailing whitespace. code_lines <- \"a <- TRUE\\n \\nb <- FALSE\" writeLines(code_lines) #> a <- TRUE #> #> b <- FALSE lint( text = code_lines, linters = trailing_whitespace_linter() ) #> ::warning file=,line=2,col=1::file=,line=2,col=1,[trailing_whitespace_linter] Remove trailing whitespace. # okay lint( text = \"x <- 1.2\", linters = trailing_whitespace_linter() ) lint( text = \"x <- 1.2 # comment about this assignment\", linters = trailing_whitespace_linter() ) code_lines <- \"a <- TRUE\\n \\nb <- FALSE\" writeLines(code_lines) #> a <- TRUE #> #> b <- FALSE lint( text = code_lines, linters = trailing_whitespace_linter(allow_empty_lines = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Undesirable function linter — undesirable_function_linter","title":"Undesirable function linter — undesirable_function_linter","text":"Report use undesirable functions suggest alternative.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Undesirable function linter — undesirable_function_linter","text":"","code":"undesirable_function_linter( fun = default_undesirable_functions, symbol_is_undesirable = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Undesirable function linter — undesirable_function_linter","text":"fun Named character vector. names(fun) correspond undesirable functions, values give description function undesirable. NA, additional information given lint message. Defaults default_undesirable_functions. make small customizations list, use modify_defaults(). symbol_is_undesirable Whether consider use undesirable function name symbol undesirable .","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Undesirable function linter — undesirable_function_linter","text":"best_practices, configurable, efficiency, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_function_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Undesirable function linter — undesirable_function_linter","text":"","code":"# defaults for which functions are considered undesirable names(default_undesirable_functions) #> [1] \".libPaths\" \"attach\" \"browser\" \"debug\" #> [5] \"debugcall\" \"debugonce\" \"detach\" \"library\" #> [9] \"mapply\" \"options\" \"par\" \"require\" #> [13] \"sapply\" \"setwd\" \"sink\" \"source\" #> [17] \"structure\" \"Sys.setenv\" \"Sys.setlocale\" \"trace\" #> [21] \"undebug\" \"untrace\" # will produce lints lint( text = \"sapply(x, mean)\", linters = undesirable_function_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"sapply\". As an alternative, use vapply() with an appropriate `FUN.VALUE=` argument to obtain type-stable simplification. lint( text = \"log10(x)\", linters = undesirable_function_linter(fun = c(\"log10\" = NA)) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"log10\". lint( text = \"log10(x)\", linters = undesirable_function_linter(fun = c(\"log10\" = \"use log()\")) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"log10\". As an alternative, use log(). lint( text = 'dir <- \"path/to/a/directory\"', linters = undesirable_function_linter(fun = c(\"dir\" = NA)) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[undesirable_function_linter] Avoid undesirable function \"dir\". # okay lint( text = \"vapply(x, mean, FUN.VALUE = numeric(1))\", linters = undesirable_function_linter() ) lint( text = \"log(x, base = 10)\", linters = undesirable_function_linter(fun = c(\"log10\" = \"use log()\")) ) lint( text = 'dir <- \"path/to/a/directory\"', linters = undesirable_function_linter(fun = c(\"dir\" = NA), symbol_is_undesirable = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Undesirable operator linter — undesirable_operator_linter","title":"Undesirable operator linter — undesirable_operator_linter","text":"Report use undesirable operators, e.g. ::: <<- suggest alternative.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Undesirable operator linter — undesirable_operator_linter","text":"","code":"undesirable_operator_linter(op = default_undesirable_operators)"},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Undesirable operator linter — undesirable_operator_linter","text":"op Named character vector. names(op) correspond undesirable operators, values give description operator undesirable. NA, additional information given lint message. Defaults default_undesirable_operators. make small customizations list, use modify_defaults().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Undesirable operator linter — undesirable_operator_linter","text":"best_practices, configurable, efficiency, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/undesirable_operator_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Undesirable operator linter — undesirable_operator_linter","text":"","code":"# defaults for which functions are considered undesirable names(default_undesirable_operators) #> [1] \"->>\" \":::\" \"<<-\" # will produce lints lint( text = \"a <<- log(10)\", linters = undesirable_operator_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[undesirable_operator_linter] Avoid undesirable operator `<<-`. It assigns outside the current environment in a way that can be hard to reason about. Prefer fully-encapsulated functions wherever possible, or, if necessary, assign to a specific environment with assign(). Recall that you can create an environment at the desired scope with new.env(). lint( text = \"mtcars$wt\", linters = undesirable_operator_linter(op = c(\"$\" = \"As an alternative, use the `[[` accessor.\")) ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[undesirable_operator_linter] Avoid undesirable operator `$`. As an alternative, use the `[[` accessor. # okay lint( text = \"a <- log(10)\", linters = undesirable_operator_linter() ) lint( text = 'mtcars[[\"wt\"]]', linters = undesirable_operator_linter(op = c(\"$\" = NA)) ) lint( text = 'mtcars[[\"wt\"]]', linters = undesirable_operator_linter(op = c(\"$\" = \"As an alternative, use the `[[` accessor.\")) )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Unneeded concatenation linter — unnecessary_concatenation_linter","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"Check c() function used without arguments single constant.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"","code":"unnecessary_concatenation_linter(allow_single_expression = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"allow_single_expression Logical, default TRUE. FALSE, one-expression usages c() always linted, e.g. c(x) c(matrix(...)). cases, c() used side-effect stripping non-name attributes; usually preferable use readable .vector() instead. .vector() always preferable, example environments (especially, R6 objects), case list() better alternative.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"configurable, efficiency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_concatenation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Unneeded concatenation linter — unnecessary_concatenation_linter","text":"","code":"# will produce lints lint( text = \"x <- c()\", linters = unnecessary_concatenation_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[unnecessary_concatenation_linter] Replace unnecessary c() by NULL or, whenever possible, vector() seeded with the correct type and/or length. lint( text = \"x <- c(TRUE)\", linters = unnecessary_concatenation_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[unnecessary_concatenation_linter] Remove unnecessary c() of a constant. lint( text = \"x <- c(1.5 + 2.5)\", linters = unnecessary_concatenation_linter(allow_single_expression = FALSE) ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[unnecessary_concatenation_linter] Remove unnecessary c() of a constant expression. Replace with as.vector() if c() is used to strip attributes, e.g. in converting an array to a vector. # okay lint( text = \"x <- NULL\", linters = unnecessary_concatenation_linter() ) # In case the intent here was to seed a vector of known size lint( text = \"x <- integer(4L)\", linters = unnecessary_concatenation_linter() ) lint( text = \"x <- TRUE\", linters = unnecessary_concatenation_linter() ) lint( text = \"x <- c(1.5 + 2.5)\", linters = unnecessary_concatenation_linter(allow_single_expression = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"Using anonymous function , e.g., lapply() always necessary, e.g. lapply(DF, sum) lapply(DF, function(x) sum(x)) former readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"","code":"unnecessary_lambda_linter(allow_comparison = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"allow_comparison Logical, default FALSE. TRUE, lambdas like function(x) foo(x) == 2, foo can extracted \"mapping\" function == vectorized instead called repeatedly, linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"Cases like lapply(x, \\(xi) grep(\"ptn\", xi)) excluded , though anonymous function can avoided, always readable.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"best_practices, configurable, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_lambda_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of anonymous functions in iteration functions when unnecessary — unnecessary_lambda_linter","text":"","code":"# will produce lints lint( text = \"lapply(list(1:3, 2:4), function(xi) sum(xi))\", linters = unnecessary_lambda_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[unnecessary_lambda_linter] Pass sum directly as a symbol to lapply() instead of wrapping it in an unnecessary anonymous function. For example, prefer lapply(DF, sum) to lapply(DF, function(x) sum(x)). lint( text = \"sapply(x, function(xi) xi == 2)\", linters = unnecessary_lambda_linter() ) lint( text = \"sapply(x, function(xi) sum(xi) > 0)\", linters = unnecessary_lambda_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[unnecessary_lambda_linter] Compare to a constant after calling sapply() to get the full benefits of vectorization. Prefer sapply(x, foo) == 2 over sapply(x, function(xi) foo(xi) == 2, logical(1L)). # okay lint( text = \"lapply(list(1:3, 2:4), sum)\", linters = unnecessary_lambda_linter() ) lint( text = 'lapply(x, function(xi) grep(\"ptn\", xi))', linters = unnecessary_lambda_linter() ) lint( text = \"lapply(x, function(xi) data.frame(col = xi))\", linters = unnecessary_lambda_linter() ) lint( text = \"sapply(x, function(xi) xi == 2)\", linters = unnecessary_lambda_linter(allow_comparison = TRUE) ) lint( text = \"sapply(x, function(xi) sum(xi) > 0)\", linters = unnecessary_lambda_linter(allow_comparison = TRUE) ) lint( text = \"sapply(x, function(xi) sum(abs(xi)) > 10)\", linters = unnecessary_lambda_linter() ) lint( text = \"sapply(x, sum) > 0\", linters = unnecessary_lambda_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block instances of unnecessary nesting — unnecessary_nesting_linter","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"Excessive nesting harms readability. Use helper functions early returns reduce nesting wherever possible.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"","code":"unnecessary_nesting_linter( allow_assignment = TRUE, allow_functions = c(\"switch\", \"try\", \"tryCatch\", \"withCallingHandlers\", \"quote\", \"expression\", \"bquote\", \"substitute\", \"with_parameters_test_that\", \"reactive\", \"observe\", \"observeEvent\", \"renderCachedPlot\", \"renderDataTable\", \"renderImage\", \"renderPlot\", \"renderPrint\", \"renderTable\", \"renderText\", \"renderUI\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"allow_assignment Logical, default TRUE, case braced expressions consisting single assignment skipped. FALSE, braced expressions one child expression linted. TRUE case facilitates interaction implicit_assignment_linter() certain cases implicit assignment necessary, braced assignment used distinguish assignment. See examples. allow_functions Character vector functions always allow one-child braced expressions. testthat::test_that() always allowed testthat requires braced expression code argument. defaults similarly compute expressions way worth highlighting em-bracing , even one expression, switch() allowed use control flow analogous /else.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"best_practices, configurable, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nesting_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block instances of unnecessary nesting — unnecessary_nesting_linter","text":"","code":"# will produce lints code <- \"if (A) {\\n stop('A is bad!')\\n} else {\\n do_good()\\n}\" writeLines(code) #> if (A) { #> stop('A is bad!') #> } else { #> do_good() #> } lint( text = code, linters = unnecessary_nesting_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unnecessary_nesting_linter] Reduce the nesting of this if/else statement by unnesting the portion without an exit clause (i.e., stop(), return(), abort(), quit(), q()). code <- \"tryCatch(\\n {\\n foo()\\n },\\n error = identity\\n)\" writeLines(code) #> tryCatch( #> { #> foo() #> }, #> error = identity #> ) lint( text = code, linters = unnecessary_nesting_linter() ) code <- \"expect_warning(\\n {\\n x <- foo()\\n },\\n 'warned'\\n)\" writeLines(code) #> expect_warning( #> { #> x <- foo() #> }, #> 'warned' #> ) lint( text = code, linters = unnecessary_nesting_linter(allow_assignment = FALSE) ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[unnecessary_nesting_linter] Reduce the nesting of this statement by removing the braces {}. writeLines(\"if (x) { \\n if (y) { \\n return(1L) \\n } \\n}\") #> if (x) { #> if (y) { #> return(1L) #> } #> } lint( text = \"if (x) { \\n if (y) { \\n return(1L) \\n } \\n}\", linters = unnecessary_nesting_linter() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[unnecessary_nesting_linter] Don't use nested `if` statements, where a single `if` with the combined conditional expression will do. For example, instead of `if (x) { if (y) { ... }}`, use `if (x && y) { ... }`. lint( text = \"my_quote({x})\", linters = unnecessary_nesting_linter() ) # okay code <- \"if (A) {\\n stop('A is bad because a.')\\n} else {\\n stop('!A is bad too.')\\n}\" writeLines(code) #> if (A) { #> stop('A is bad because a.') #> } else { #> stop('!A is bad too.') #> } lint( text = code, linters = unnecessary_nesting_linter() ) code <- \"capture.output({\\n foo()\\n})\" writeLines(code) #> capture.output({ #> foo() #> }) lint( text = code, linters = unnecessary_nesting_linter() ) code <- \"expect_warning(\\n {\\n x <- foo()\\n },\\n 'warned'\\n)\" writeLines(code) #> expect_warning( #> { #> x <- foo() #> }, #> 'warned' #> ) lint( text = code, linters = unnecessary_nesting_linter() ) writeLines(\"if (x && y) { \\n return(1L) \\n}\") #> if (x && y) { #> return(1L) #> } lint( text = \"if (x && y) { \\n return(1L) \\n}\", linters = unnecessary_nesting_linter() ) writeLines(\"if (x) { \\n y <- x + 1L\\n if (y) { \\n return(1L) \\n } \\n}\") #> if (x) { #> y <- x + 1L #> if (y) { #> return(1L) #> } #> } lint( text = \"if (x) { \\n y <- x + 1L\\n if (y) { \\n return(1L) \\n } \\n}\", linters = unnecessary_nesting_linter() ) lint( text = \"my_quote({x})\", linters = unnecessary_nesting_linter(allow_functions = \"my_quote\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"argument placeholder . magrittr pipelines unnecessary passed first positional argument; using can cause confusion impacts readability.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"","code":"unnecessary_placeholder_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"true forward (%>%), assignment (%<>%), tee (%T>%) operators.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_placeholder_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of pipeline placeholders if unnecessary — unnecessary_placeholder_linter","text":"","code":"# will produce lints lint( text = \"x %>% sum(., na.rm = TRUE)\", linters = unnecessary_placeholder_linter() ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[unnecessary_placeholder_linter] Don't use the placeholder (`.`) when it's not needed, i.e., when it's only used as the first positional argument in a pipeline step. # okay lint( text = \"x %>% sum(na.rm = TRUE)\", linters = unnecessary_placeholder_linter() ) lint( text = \"x %>% lm(data = ., y ~ z)\", linters = unnecessary_placeholder_linter() ) lint( text = \"x %>% outer(., .)\", linters = unnecessary_placeholder_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block unreachable code and comments following return statements — unreachable_code_linter","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"Code e.g. return() stop() deterministically false conditional loops like (FALSE) reached; typically vestigial code left refactoring sandboxing code, fine exploration, ultimately checked . Comments meant posterity placed final return().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"","code":"unreachable_code_linter( allow_comment_regex = getOption(\"covr.exclude_end\", \"# nocov end\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"allow_comment_regex Character vector regular expressions identify comments exclude finding unreachable terminal comments. default, includes default \"skip region\" end marker {covr} (option \"covr.exclude_end\", \"# nocov end\" unset). end marker {lintr} (settings$exclude_end) always included. Note regexes include initial comment character #.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"best_practices, configurable, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unreachable_code_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block unreachable code and comments following return statements — unreachable_code_linter","text":"","code":"# will produce lints code_lines <- \"f <- function() {\\n return(1 + 1)\\n 2 + 2\\n}\" writeLines(code_lines) #> f <- function() { #> return(1 + 1) #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=3,col=3::file=,line=3,col=3,[unreachable_code_linter] Remove code and comments coming after return() or stop(). code_lines <- \"if (FALSE) {\\n 2 + 2\\n}\" writeLines(code_lines) #> if (FALSE) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unreachable_code_linter] Remove code inside a conditional loop with a deterministically false condition. code_lines <- \"while (FALSE) {\\n 2 + 2\\n}\" writeLines(code_lines) #> while (FALSE) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unreachable_code_linter] Remove code inside a conditional loop with a deterministically false condition. code_lines <- \"f <- function() {\\n return(1)\\n # end skip\\n}\" writeLines(code_lines) #> f <- function() { #> return(1) #> # end skip #> } lint( text = code_lines, linters = unreachable_code_linter() ) #> ::warning file=,line=3,col=3::file=,line=3,col=3,[unreachable_code_linter] Remove code and comments coming after return() or stop(). # okay code_lines <- \"f <- function() {\\n return(1 + 1)\\n}\" writeLines(code_lines) #> f <- function() { #> return(1 + 1) #> } lint( text = code_lines, linters = unreachable_code_linter() ) code_lines <- \"if (foo) {\\n 2 + 2\\n}\" writeLines(code_lines) #> if (foo) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) code_lines <- \"while (foo) {\\n 2 + 2\\n}\" writeLines(code_lines) #> while (foo) { #> 2 + 2 #> } lint( text = code_lines, linters = unreachable_code_linter() ) code_lines <- \"f <- function() {\\n return(1)\\n # end skip\\n}\" writeLines(code_lines) #> f <- function() { #> return(1) #> # end skip #> } lint( text = code_lines, linters = unreachable_code_linter(allow_comment_regex = \"# end skip\") )"},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that imported packages are actually used — unused_import_linter","title":"Check that imported packages are actually used — unused_import_linter","text":"Check imported packages actually used","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that imported packages are actually used — unused_import_linter","text":"","code":"unused_import_linter( allow_ns_usage = FALSE, except_packages = c(\"bit64\", \"data.table\", \"tidyverse\"), interpret_glue = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that imported packages are actually used — unused_import_linter","text":"allow_ns_usage Suppress lints packages used via namespace. FALSE default pkg::fun() require library(pkg). can use requireNamespace(\"pkg\") ensure package installed without attaching . except_packages Character vector packages ignored. usually attached side effects. interpret_glue TRUE, interpret glue::glue() calls avoid false positives caused local variables used glue expression.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check that imported packages are actually used — unused_import_linter","text":"best_practices, common_mistakes, configurable, executing","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unused_import_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check that imported packages are actually used — unused_import_linter","text":"","code":"# will produce lints code_lines <- \"library(dplyr)\\n1 + 1\" writeLines(code_lines) #> library(dplyr) #> 1 + 1 lint( text = code_lines, linters = unused_import_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unused_import_linter] Package 'dplyr' is attached but never used. code_lines <- \"library(dplyr)\\ndplyr::tibble(a = 1)\" writeLines(code_lines) #> library(dplyr) #> dplyr::tibble(a = 1) lint( text = code_lines, linters = unused_import_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[unused_import_linter] Don't attach package 'dplyr', which is only used by namespace. Check that it is installed using loadNamespace() instead. # okay code_lines <- \"library(dplyr)\\ntibble(a = 1)\" writeLines(code_lines) #> library(dplyr) #> tibble(a = 1) lint( text = code_lines, linters = unused_import_linter() ) code_lines <- \"library(dplyr)\\ndplyr::tibble(a = 1)\" writeLines(code_lines) #> library(dplyr) #> dplyr::tibble(a = 1) lint( text = code_lines, linters = unused_import_linter(allow_ns_usage = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":null,"dir":"Reference","previous_headings":"","what":"Use lintr in your project — use_lintr","title":"Use lintr in your project — use_lintr","text":"Create minimal lintr config file starting point customization","code":""},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Use lintr in your project — use_lintr","text":"","code":"use_lintr(path = \".\", type = c(\"tidyverse\", \"full\"))"},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Use lintr in your project — use_lintr","text":"path Path project root, .lintr file created. .lintr file already exists, error thrown. type kind configuration create? tidyverse creates minimal lintr config, based default linters (linters_with_defaults()). suitable following tidyverse style guide. full creates lintr config using available linters via all_linters().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Use lintr in your project — use_lintr","text":"Path generated configuration, invisibly.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/use_lintr.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Use lintr in your project — use_lintr","text":"","code":"if (FALSE) { # use the default set of linters lintr::use_lintr() # or try all linters lintr::use_lintr(type = \"full\") # then lintr::lint_dir() }"},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"Usage & conditional statements error-prone inefficient. condition (condition) expr must always length 1, case && preferred. Ditto | vs. ||.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"","code":"vector_logic_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"linter covers inputs () () conditions testthat::expect_true() testthat::expect_false(). Note & | generics, possible && / || perfect substitutes & method dispatch incompatible way. Moreover, wary code may side effects, commonly assignments. Consider ((<- foo(x)) | (b <- bar(y))) { ... } vs. ((<- foo(x)) || (b <- bar(y))) { ... }. || exits early, TRUE, second condition never evaluated b assigned. usage allowed Tidyverse style guide, code can easily refactored pulling assignment outside condition, using || still preferable.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"best_practices, common_mistakes, default, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/vector_logic_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Enforce usage of scalar logical operators in conditional statements — vector_logic_linter","text":"","code":"# will produce lints lint( text = \"if (TRUE & FALSE) 1\", linters = vector_logic_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[vector_logic_linter] Use `&&` in conditional expressions. lint( text = \"if (TRUE && (TRUE | FALSE)) 4\", linters = vector_logic_linter() ) #> ::warning file=,line=1,col=19::file=,line=1,col=19,[vector_logic_linter] Use `||` in conditional expressions. lint( text = \"filter(x, A && B)\", linters = vector_logic_linter() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[vector_logic_linter] Use `&` in subsetting expressions. # okay lint( text = \"if (TRUE && FALSE) 1\", linters = vector_logic_linter() ) lint( text = \"if (TRUE && (TRUE || FALSE)) 4\", linters = vector_logic_linter() ) lint( text = \"filter(x, A & B)\", linters = vector_logic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of grep over which(grepl(.)) — which_grepl_linter","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"(grepl(pattern, x)) grep(pattern, x), harder read requires two passes vector.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"","code":"which_grepl_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"consistency, efficiency, readability, regex","code":""},{"path":"https://lintr.r-lib.org/dev/reference/which_grepl_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of grep over which(grepl(.)) — which_grepl_linter","text":"","code":"# will produce lints lint( text = \"which(grepl('^a', x))\", linters = which_grepl_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[which_grepl_linter] grep(pattern, x) is better than which(grepl(pattern, x)). # okay lint( text = \"which(grepl('^a', x) | grepl('^b', x))\", linters = which_grepl_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Whitespace linter — whitespace_linter","title":"Whitespace linter — whitespace_linter","text":"Check correct character used indentation.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Whitespace linter — whitespace_linter","text":"","code":"whitespace_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Whitespace linter — whitespace_linter","text":"Currently, supports linting presence tabs. Much ink spilled topic, encourage check references information.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Whitespace linter — whitespace_linter","text":"https://www.jwz.org/doc/tabs-vs-spaces.html https://blog.codinghorror.com/death---space-infidels/","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Whitespace linter — whitespace_linter","text":"consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/whitespace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Whitespace linter — whitespace_linter","text":"","code":"# will produce lints lint( text = \"\\tx\", linters = whitespace_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[whitespace_linter] Use spaces to indent, not tabs. # okay lint( text = \" x\", linters = whitespace_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"Convenience function converting nodes matched XPath-based linter logic Lint() object return.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"","code":"xml_nodes_to_lints( xml, source_expression, lint_message, type = c(\"style\", \"warning\", \"error\"), column_number_xpath = range_start_xpath, range_start_xpath = \"number(./@col1)\", range_end_xpath = \"number(./@col2)\" )"},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"xml xml_node object (generate one Lint) xml_nodeset object (generate several Lints), e.g. returned xml2::xml_find_all() xml2::xml_find_first() list xml_node objects. source_expression source expression object, e.g. returned typically lint(), generally get_source_expressions(). lint_message message included message Lint object. lint_message character vector length xml, -th lint given -th message. type type lint. column_number_xpath XPath expression return column number location lint. Defaults start range matched range_start_xpath. See details information. range_start_xpath XPath expression return range start location lint. Defaults start expression matched xml. See details information. range_end_xpath XPath expression return range end location lint. Defaults end expression matched xml. See details information.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"xml_nodes, lint. xml_nodesets, lints (list lints).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xml_nodes_to_lints.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert an XML node or nodeset into a Lint — xml_nodes_to_lints","text":"location XPaths, column_number_xpath, range_start_xpath range_end_xpath evaluated using xml2::xml_find_num() usually form \"number(./relative/xpath)\". Note location line number changed lints spanning multiple lines ignore range_end_xpath. column_number_xpath range_start_xpath assumed always refer locations starting line xml node.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":null,"dir":"Reference","previous_headings":"","what":"Get the name of the function matched by an XPath — xp_call_name","title":"Get the name of the function matched by an XPath — xp_call_name","text":"Often, helpful tailor message lint record function matched lint logic. function encapsulates logic pull matched call common situations.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get the name of the function matched by an XPath — xp_call_name","text":"","code":"xp_call_name(expr, depth = 1L, condition = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get the name of the function matched by an XPath — xp_call_name","text":"expr xml_node xml_nodeset, e.g. xml2::xml_find_all(). depth Integer, default 1L. deep AST represented expr look find call? default, assume expr matched node corresponding node found directly. depth = 0L means expr matched directly SYMBOL_FUNCTION_CALL; depth > 1L means depth total nodes must traversed finding call. condition additional (XPath condition SYMBOL_FUNCTION_CALL required match. default (NULL) condition. See examples.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/xp_call_name.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get the name of the function matched by an XPath — xp_call_name","text":"","code":"xml_from_code <- function(str) { xml2::read_xml(xmlparsedata::xml_parse_data(parse(text = str, keep.source = TRUE))) } xml <- xml_from_code(\"sum(1:10)\") xp_call_name(xml, depth = 2L) #> [1] \"sum\" xp_call_name(xml2::xml_find_first(xml, \"expr\")) #> [1] \"sum\" xml <- xml_from_code(c(\"sum(1:10)\", \"sd(1:10)\")) xp_call_name(xml, depth = 2L, condition = \"text() = 'sum'\") #> [1] \"sum\""},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block obvious ","title":"Block obvious ","text":"Yoda tests use (expected, actual) instead common (actual, expected). always possible detect statically; linter focuses simple case testing expression literal value, e.g. (1L, foo(x)) (foo(x), 1L).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block obvious ","text":"","code":"yoda_test_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block obvious ","text":"best_practices, package_development, pkg_testthat, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/yoda_test_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block obvious ","text":"","code":"# will produce lints lint( text = \"expect_equal(2, x)\", linters = yoda_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[yoda_test_linter] Compare objects in tests in the order 'actual', 'expected', not the reverse. For example, do expect_equal(foo(x), 2L) instead of expect_equal(2L, foo(x)). lint( text = 'expect_identical(\"a\", x)', linters = yoda_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[yoda_test_linter] Compare objects in tests in the order 'actual', 'expected', not the reverse. For example, do expect_identical(foo(x), 2L) instead of expect_identical(2L, foo(x)). # okay lint( text = \"expect_equal(x, 2)\", linters = yoda_test_linter() ) lint( text = 'expect_identical(x, \"a\")', linters = yoda_test_linter() )"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecations--breaking-changes-development-version","dir":"Changelog","previous_headings":"","what":"Deprecations & breaking changes","title":"lintr (development version)","text":"source_file= argument ids_with_token() with_id(). Passing linters name non-\"linter\"-classed functions. linter= argument Lint(). Linters closed_curly_linter(), open_curly_linter(), paren_brace_linter(), semicolon_terminator_linter().. with_defaults(). Linters closed_curly_linter(), open_curly_linter(), paren_brace_linter(), semicolon_terminator_linter(). Helper with_defaults(). all_linters() signature all_linters(..., packages) rather all_linters(packages, ...) (#2332, @MichaelChirico). forces packages= supplied name break users rely supplying packages= positionally, found none searching GitHub. Adjusted various lint messages consistency readability (#1330, @MichaelChirico). general, favor lint messages phrased like “Action, reason” “” piece message front--center. may breaking change code tests specific phrasing lints. extraction_operator_linter() deprecated. Although switching $ [[ robustness benefits package code, can lead non-idiomatic code many contexts (e.g. R6 classes, Shiny applications, etc.) (#2409, @IndrajeetPatil). enable detection $ operator extraction partial matching, use options(warnPartialMatchDollar = TRUE). unnecessary_nested_if_linter() deprecated subsumed new/general unnecessary_nesting_linter(). Drop support posting GitHub comments inside GitHub comment bot, Travis, Wercker, Jenkins CI tools (spurred #2148, @MichaelChirico). rely GitHub Actions linting CI, don’t see active users relying alternatives. welcome encourage community contributions get support different CI system going . cyclocomp_linter() longer part default linters (#2555, @IndrajeetPatil) tidyverse style guide doesn’t contain guidelines meeting certain complexity requirements. Note users cyclocomp_linter() configs may now need install {cyclocomp} intentionally, particular CI/CD pipelines. scalar_in_linter now configurable allow %% like operators linted. data.table operator %chin% longer linted default; use in_operators = \"%chin%\" continue linting . (@F-Noelle)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-development-version","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr (development version)","text":"expect_identical_linter() also skips expect_equal() comparison negative non-integers like -1.034 (#2411, @Bisaloo). parity fix since positive reals always skipped “high-precision” comparisons typically done get tests within tolerance, expect_identical() great substitution. object_name_linter() longer errors user-supplied regexes= capture groups (#2188, @MichaelChirico). .lintr config validation correctly accepts regular expressions compile perl = TRUE (#2375, @MichaelChirico). always valid (since rex::re_matches(), powers lint exclusion logic, also uses setting), new -front validation v3.1.1 incorrectly used perl = FALSE. .lintr configs set option lintr.linter_file environment variable R_LINTR_LINTER_FILE can point subdirectories (#2512, @MichaelChirico). indentation_linter() returns ranges[1L]==1L offending line 0 spaces (#2550, @MichaelChirico). literal_coercion_linter() doesn’t surface warning NAs coercion code like .integer(\"\") (#2566, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-default-linters-development-version","dir":"Changelog","previous_headings":"","what":"Changes to default linters","title":"lintr (development version)","text":"New default linter return_linter() style guide rule terminal returns left implicit (#1100, #2343, #2354, #2356, @MEO265 @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-development-version","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr (development version)","text":"helpful errors invalid configs (#2253, @MichaelChirico). encourage packages attached library(symbol), library(\"symbol\", character.= TRUE) “vectorized” approaches looping package names (part #884, @MichaelChirico). discourage many consecutive calls suppressMessages() suppressPackageStartupMessages() (part #884, @MichaelChirico). return_style (\"implicit\" default) checks functions confirm specified return style \"implicit\" \"explicit\" (#2271 part #884, @MichaelChirico, @AshesITR @MEO265). allow_implicit_else (default TRUE) , FALSE, checks terminal statements paired corresponding else statement (part #884, @MichaelChirico). return_functions customize functions equivalent return() “exit” clauses, e.g. rlang::abort() can considered addition default functions like stop() q() base (#2271 part #884, @MichaelChirico @MEO265). except customize functions ignored entirely (.e., whether return specified style checked; #2271 part #884, @MichaelChirico @MEO265). Namespace hooks like .onAttach() .onLoad() always ignored. except_regex, purpose except=, filters functions pattern. motivated {RUnit}, test suites based unit test functions matched pattern, e.g. ^Test, explicit return may awkward (#2335, @MichaelChirico). unnecessary_lambda_linter extended encourage vectorized comparisons possible, e.g. sapply(x, sum) > 0 instead sapply(x, function(x) sum(x) > 0) (part #884, @MichaelChirico). Toggle behavior argument allow_comparison. backport_linter() slightly faster moving expensive computations outside linting function (#2339, #2348, @AshesITR @MichaelChirico). Linter() new argument linter_level (default NA). used lint() efficiently check expression levels idiom (!is_lint_level(...)) { return(list()) } (#2351, @AshesITR). string_boundary_linter() recognizes regular expression calls like grepl(\"^abc$\", x) can replaced using == instead (#1613, @MichaelChirico). unreachable_code_linter() argument allow_comment_regex customizing “terminal” comments exclude (#2327, @MichaelChirico). # nolint end comments always excluded, {covr} exclusions (e.g. # nocov end) default. format() print() methods lint lints classes get new option width control printing width lint messages (#1884, @MichaelChirico). default controlled new option lintr.format_width; unset, wrapping occurs (matching earlier behavior). implicit_assignment_linter() gets custom message case using ( induce printing like (x <- foo()); use explicit call print() clarity (#2257, @MichaelChirico). New function node caching big efficiency gains linters (e.g. overall lint_package() improvement 14-27% core linting improvement 30%; #2357, @AshesITR). linters written around function usage, XPath performance searching many functions poor. new xml_find_function_calls() entry get_source_expressions() output caches function call nodes instead. See vignette creating linters details use . todo_comment_linter() new argument except_regex setting valid TODO comments, e.g. forcing TODO comments linked GitHub issues like TODO(#154) (#2047, @MichaelChirico). vector_logic_linter() extended recognize incorrect usage scalar operators && || inside subsetting expressions like dplyr::filter(x, && B) (#2166, @MichaelChirico). any_is_na_linter() extended catch unusual usage NA %% x (#2113, @MichaelChirico). make_linter_from_xpath() errors front lint_message missing (instead delaying error linter used, #2541, @MichaelChirico). paste_linter() extended recommend using paste() instead paste0() simply aggregating character vector collapse=, .e., sep= irrelevant (#1108, @MichaelChirico). expect_no_lint() added new function cover typical use case expecting lint message, akin recent {testthat} functions like expect_no_warning() (#2580, @F-Noelle).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-development-version","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr (development version)","text":"condition_call_linter() ensuring consistent use call. warning() stop(). default call. = FALSE follows tidyverse guidance displaying call (#2226, @Bisaloo) sample_int_linter() encouraging sample.int(n, ...) equivalents like sample(1:n, ...) (part #884, @MichaelChirico). stopifnot_all_linter() discourages tests () like stopifnot((x > 0)); stopifnot() runs () , uses better error message (part #884, @MichaelChirico). comparison_negation_linter() discouraging negated comparisons direct negation preferable, e.g. !(x == y) x != y (part #884, @MichaelChirico). nzchar_linter() encouraging nzchar() test empty strings, e.g. nchar(x) > 0 can nzchar(x) (part #884, @MichaelChirico). terminal_close_linter() discouraging using close() end functions (part #884, @MichaelChirico). usages robust errors, close() run intended. Put close() .exit() hook, use {withr} manage connections proper cleanup. rep_len_linter() encouraging use rep_len() directly instead rep(x, length.= n) (part #884, @MichaelChirico). which_grepl_linter() discouraging (grepl(ptn, x)) favor directly using grep(ptn, x) (part #884, @MichaelChirico). list_comparison_linter() discouraging comparisons output lapply(), e.g. lapply(x, sum) > 10 (part #884, @MichaelChirico). print_linter() discouraging usage print() string literals like print(\"Reached \") print(paste(\"Found\", nrow(DF), \"rows.\")) (#1894, @MichaelChirico). unnecessary_nesting_linter() discouraging overly-nested code early return eliminated sub-expression (inside ‘{’) preferable (#2317, #2334 part #884, @MichaelChirico). consecutive_mutate_linter() encouraging consecutive calls dplyr::mutate() combined (part #884, @MichaelChirico). if_switch_linter() encouraging switch() repeated /else tests (#2322 part #884, @MichaelChirico). nested_pipe_linter() discouraging pipes within pipes, e.g. df1 %>% inner_join(df2 %>% select(, b)) (part #884, @MichaelChirico). nrow_subset_linter() discouraging usage like nrow(subset(x, conditions)) favor something like (x, sum(conditions)) doesn’t require full subset x (#2313, #2314 part #884, @MichaelChirico). pipe_return_linter() discouraging usage return() inside {magrittr} pipeline (part #884, @MichaelChirico). one_call_pipe_linter() discouraging one-step pipelines like x |> .character() (#2330 part #884, @MichaelChirico). object_overwrite_linter() discouraging re-use upstream package exports local variables (#2344, #2346 part #884, @MichaelChirico @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-positives-development-version","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false positives","title":"lintr (development version)","text":"object_name_linter() object_length_linter() ignore {rlang} name injection like x |> mutate(\"{new_name}\" := foo(col)) (#1926, @MichaelChirico). checking applied cases. {data.table} -place assignments like DT[, \"sPoNGeBob\" := \"friend\"] still eligible lints.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"notes-development-version","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr (development version)","text":"user-facing messages now prepared using cli package (#2418, @IndrajeetPatil). messages reviewed updated informative consistent. {lintr} now depends R version 4.0.0. already implicitly due recursive upstream dependencies requiring version; ’ve simply made dependency explicit -front (#2569, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-312","dir":"Changelog","previous_headings":"","what":"lintr 3.1.2","title":"lintr 3.1.2","text":"CRAN release: 2024-03-25","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-positives-3-1-2","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false positives","title":"lintr 3.1.2","text":"unreachable_code_linter() ignores reachable code inline functions like function(x) (x > 2) stop() else x (#2259, @MEO265). ignores extractions explicit returns like lapply(l, function(x) foo(x)$bar) (#2258, @MichaelChirico). ignores calls RHS operators like lapply(l, function(x) \"\" %% names(x)) (#2310, @MichaelChirico). vector_logic_linter() recognizes cases bitwise &/| used correctly (#1453, @MichaelChirico). expect_comparison_linter() ignores faulty usage like expect_true(x, y > z) (#2083, @MichaelChirico). Note y > z passed info= argument, likely mistake. consecutive_assertion_linter() ignores cases second assertion follows intervening assignment = (#2444, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-negatives-3-1-2","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false negatives","title":"lintr 3.1.2","text":"missing_argument_linter() catches missing arguments calls several, e.g. foo(,,) gives 3 lints instead 2 (#2399, @MichaelChirico). duplicate_argument_linter() longer misses cases duplicate arguments comment comes argument name = (#2402, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"notes-3-1-2","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr 3.1.2","text":"Fixed test assuming specific parser error message recently changed r-devel (#2527, @IndrajeetPatil). @MichaelChirico taken CRAN maintainer duties package. Many thanks @jimhester 10 years 15 releases wearing hat!!","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-311","dir":"Changelog","previous_headings":"","what":"lintr 3.1.1","title":"lintr 3.1.1","text":"CRAN release: 2023-11-07","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"breaking-changes-3-1-1","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"lintr 3.1.1","text":"infix_spaces_linter() distinguishes <-, :=, <<- ->, ->>, .e. infix_spaces_linter(exclude_operators = \"->\") longer exclude ->> (#2115, @MichaelChirico). change breaking users relying manually-supplied exclude_operators containing \"<-\" also exclude := <<-. fix manually supply \":=\" \"<<-\" well. don’t expect change affect many users, fix simple, new behavior much transparent, including breakage minor release. Removed find_line() find_column() entries get_source_expressions() expression-level objects. marked deprecated since version 3.0.0. users found GitHub. also validate config files -front make clearer invalid configs present (#2195, @MichaelChirico). warning “invalid” settings, .e., settings part ?default_settings. think likely affect users declaring settings R, since variable defined config ’s setting must removed make clearer variables settings vs. ancillary.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-1-1","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.1.1","text":"sprintf_linter() doesn’t error cases whitespace ... arguments significant, e.g. sprintf(\"%s\", () \"\" else y), won’t parse whitespace removed (#2131, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-default-linters-3-1-1","dir":"Changelog","previous_headings":"","what":"Changes to default linters","title":"lintr 3.1.1","text":"assignment_linter() lints {magrittr} assignment pipe %<>% (#2008, @MichaelChirico). can deactivated setting new argument allow_pipe_assign TRUE. assumes glue() glue::glue() interpret_glue=TRUE (#2032, @MichaelChirico). finds function usages, including infix usage, inside glue() calls avoid false positives “unused objects” (#2029 #2069, @MichaelChirico). object_name_linter() longer attempts lint strings function calls LHS assignments (#1466, @MichaelChirico). infix_spaces_linter() allows finer control linting = different scenarios using parse tags EQ_ASSIGN, EQ_SUB, EQ_FORMALS (#1977, @MichaelChirico). equals_na_linter() checks x %% NA, convoluted form .na(x) (#2088, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-3-1-1","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr 3.1.1","text":"New exclusion sentinel # nolint next signify next line skip linting (#1791, @MichaelChirico). usual rules apply excluding specific linters, e.g. # nolint next: assignment_linter.. exact string used match subsequent-line exclusion controlled exclude_next config entry R option \"lintr.exclude_next\". New xp_call_name() helper facilitate writing custom linters (#2023, @MichaelChirico). helper converts matched XPath R function corresponds. useful including “offending” function lint’s message. New make_linter_from_xpath() facilitate making simple linters directly single XPath (#2064, @MichaelChirico). especially helpful making --fly/exploratory linters, also extends case linter can fully defined static lint message single XPath. Toggle lint progress indicators argument show_progress lint_dir() lint_package() (#972, @MichaelChirico). default still show progress interactive() sessions. Progress also now shown “proper” progress bar (utils::txtProgressBar()), particular solves issue progress . spilling well past width screen large directories. lint(), lint_dir(), lint_package() fail gracefully user mis-spells argument name (#2134, @MichaelChirico). Quarto files (.qmd) included lint_dir() default (#2150, @dave-lovell).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr 3.1.1","text":"library_call_linter() can detect library/require calls top script (#2027, #2043, #2163, #2170, @nicholas-masel @MichaelChirico). keyword_quote_linter() finding unnecessary discouraged quoting symbols assignment, function arguments, extraction (part #884, @MichaelChirico). Quoting unnecessary target valid R name, e.g. c(\"\" = 1) can c(= 1). goes assignment (\"\" <- 1) extraction (x$\"\"). quoting necessary, linter encourages backticks (e.g. x$`b` instead x$\"b\"). length_levels_linter() using specific function nlevels() instead checking length(levels(x)) (part #884, @MichaelChirico). scalar_in_linter() discouraging %% right-hand side scalar, e.g. x %% 1 (part #884, @MichaelChirico). if_not_else_linter() encouraging statements structured () x else y instead (!) y else x (part #884, @MichaelChirico). repeat_linter() encouraging repeat infinite loops instead (TRUE) (#2106, @MEO265). length_test_linter() detects common mistake length(x == 0) meant length(x) == 0 (#1991, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"extensions-to-existing-linters-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"Extensions to existing linters","title":"lintr 3.1.1","text":"fixed_regex_linter() gains option allow_unescaped (default FALSE) toggle linting regexes requiring escapes character classes (#1689, @MichaelChirico). Thus fixed_regex_linter(allow_unescaped = TRUE) lint grepl(\"[$]\", x) grepl(\"\", x) since latter use regex special characters. line_length_linter() helpfully includes line length lint message (#2057, @MichaelChirico). conjunct_test_linter() also lints usage like dplyr::filter(x, & B) favor using dplyr::filter(x, , B) (part #884; #2110 #2078, @salim-b @MichaelChirico). Option allow_filter toggles applies. allow_filter = \"always\" drops lints entirely, \"not_dplyr\" lints calls explicitly qualified dplyr::filter(). default, \"never\", assumes unqualified calls filter() dplyr::filter(). sort_linter() checks code like x == sort(x) better served using function .unsorted() (part #884, @MichaelChirico). paste_linter() gains detection file paths better constructed file.path(), e.g. paste0(dir, \"/\", file) better file.path(dir, file) (part #884, #2082, @MichaelChirico). exactly gets linted can fine-tuned allow_file_path option (\"double_slash\" default, alternatives \"never\" \"always\"). \"always\", rules ignored. \"double_slash\", paths appearing construct URL consecutive forward slashes (/) skipped. \"never\", even URLs constructed file.path(). seq_linter() recommends rev() lint message lints like nrow(x):1 (#1542, @MichaelChirico). function_argument_linter() detects usage missing() linted argument (#1546, @MichaelChirico). simplest fix function_argument_linter() lints typically set argument NULL default, case ’s usually preferable update function logic checking missing() check .null() instead. commas_linter() gains option allow_trailing (default FALSE) allow trailing commas indexing. (#2104, @MEO265) checks code inside (FALSE) conditional loops deterministically false conditions (#1428, @ME0265). checks unreachable code inside , else, , , repeat blocks, including combinations break next statements. (#2105, @ME0265). implicit_assignment_linter() gains argument allow_lazy (default FALSE) allows optionally skipping lazy assignments like && (B <- foo()) (#2016, @MichaelChirico). unused_import_linter() gains argument interpret_glue (default TRUE) paralleling object_usage_linter() toggle whether glue::glue() expressions inspected exported object usage (#2042, @MichaelChirico). default_undesirable_functions updated also include Sys.unsetenv() structure() (#2192 #2228, @IndrajeetPatil @MichaelChirico). brace_linter() pipe_call_linter() pipe_continuation_linter() unnecessary_concatenation_linter() unnecessary_placeholder_linter() brace_linter() function_left_parentheses_linter() indentation_linter() object_length_linter() object_name_linter() package_hooks_linter() paren_body_linter() unnecessary_lambda_linter() unreachable_code_linter()","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-positives-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false positives","title":"lintr 3.1.1","text":"pipe-aware, particular removing false positives around piping {stringr} functions like x |> str_replace(fixed(\"\"), \"b\") (#1811, @MichaelChirico). Ignores non-string inputs pattern= keyword argument (#2159, @MichaelChirico). T_and_F_symbol_linter() for_loop_index_linter() literal_coercion_linter() object_name_linter() undesirable_function_linter() unreachable_code_linter() yoda_test_linter() sprintf_linter() pipe-aware, x %>% sprintf(fmt = \"%s\") longer lints (#1943, @MichaelChirico). condition_message_linter() ignores usages extracted calls like env$stop(paste(, b)) (#1455, @MichaelChirico). inner_combine_linter() longer throws length-1 calls c() like c(exp(2)) c(log(3)) (#2017, @MichaelChirico). usage discouraged unnecessary_concatenation_linter(), inner_combine_linter() per se apply. sort_linter() lints order() single vector, excluding e.g. x[order(x, y)] x[order(y, x)] (#2156, @MichaelChirico). redundant_ifelse_linter() aware dplyr::if_else()’s missing= argument, if_else(, TRUE, FALSE, missing = FALSE) doesn’t lint, if_else(, TRUE, FALSE, NA) (#1941, @MichaelChirico). Note dplyr::coalesce() tidyr::replace_na() may still preferable.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lint-accuracy-fixes-removing-false-negatives-3-1-1","dir":"Changelog","previous_headings":"New and improved features","what":"Lint accuracy fixes: removing false negatives","title":"lintr 3.1.1","text":"unreachable_code_linter() finds unreachable code even presence comment semicolon return() stop() (#2127, @MEO265). finds assignments call arguments besides first one (#2136, @MichaelChirico). finds assignments parenthetical expressions like (&& (B <- foo())) { } (#2138, @MichaelChirico). thanks @Bisaloo @strengejacke detecting regression original fix (#2231, #2247).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-310","dir":"Changelog","previous_headings":"","what":"lintr 3.1.0","title":"lintr 3.1.0","text":"CRAN release: 2023-07-19","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecations--breaking-changes-3-1-0","dir":"Changelog","previous_headings":"","what":"Deprecations & Breaking Changes","title":"lintr 3.1.0","text":".lintr files can now kept directory .github/linters better compatibility Super-Linter. Note may breaking change already config .github/linters inside subdirectory well R project’s root, since former now discovered first ignored . Please see vignette(\"lintr\") details configs discovered (#1746, @tonyk7440 @klmr). single_quotes_linter() deprecated favor generalizable quotes_linter() (#1729, @MichaelChirico). unneeded_concatentation_linter() deprecated favor unnecessary_concatenation_linter() naming consistency (#1707, @IndrajeetPatil). consecutive_stopifnot_linter() deprecated favor general (see ) consecutive_assertion_linter() (#1604, @MichaelChirico). no_tab_linter() deprecated favor whitespace_linter() naming consistency future generalization (#1954, @MichaelChirico). available_linters() prioritizes tags exclude_tags case overlap, .e., tags listed arguments included, excluded. don’t expect many people affected , old behavior made explicit documentation, make note since required changing test lintr’s suite linters_with_tags() implicitly assumed behavior. lint(), lint_dir(), lint_package() longer accept certain arguments (cache= lint(), relative_path= latter two) positionally. warning() since 3.0.0 upgraded error.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-1-0","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.1.0","text":"linters_with_tags() now includes previously missing spaces around “” listing missing linters advertised available_linters(). error message may appear e.g. update lintr version new linters don’t restart R session (#1946, @Bisaloo) fixed_regex_linter() robust errors stemming unrecognized escapes (#1545, #1845, @IndrajeetPatil). get_source_expressions() can handle Sweave/Rmarkdown documents reference chunks like <> (#779, @MichaelChirico). Note simply skipped, rather attempting retrieve reference also lint . assignment_linter() longer lints assignments braces include comments allow_trailing = FALSE (#1701, @ashbaldry) object_usage_linter() longer silently ignores usage warnings don’t contain quoted name (#1714, @AshesITR) longer fails code comments inside multi-line call glue::glue() (#1919, @MichaelChirico) namespace_linter() correctly recognizes backticked operators exported respective namespaces (like rlang::`%||%`) (#1752, @IndrajeetPatil) lint_package() correctly finds package within subdir path points anywhere within package (#1759, @AshesITR) Improved error behavior Lint(), lint() xml_nodes_to_lints() (#1427, #763, @AshesITR) Lint() validates inputs thoroughly, preventing errors print.Lints like “Error rep.int(character, length) : invalid ‘times’ value:”. lint() longer tries create expression tree unexpected end input errors, can broken. xml_nodes_to_lints() warns can’t find lint locations uses dummy locations fallback. linters_with_defaults() longer erroneously marks linter factories linters (#1725, @AshesITR). Row names available_linters() data frame now contiguous (#1781, @IndrajeetPatil). object_name_linter() allows S3 group Generics (see ?base::groupGeneric) S3 generics defined different file package (#1808, #1841, @AshesITR) object_usage_linter() improves identification exact source lint undefined variables expressions variable used symbol usual way, example formula extraction $ (#1914, @MichaelChirico). general usage warnings without location info (#1986 #1917, @AshesITR) function_left_parentheses_linter() produces specific lint (longer fails) opening parenthesis different line function call name (#1953, @MichaelChirico). Thanks also @IndrajeetPatil @lorenzwalthert identifying regression initial fix, #1963.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-defaults-3-1-0","dir":"Changelog","previous_headings":"","what":"Changes to defaults","title":"lintr 3.1.0","text":"Set default except argument duplicate_argument_linter() c(\"mutate\", \"transmute\"). allows sequential updates like x |> mutate(= b + 1, = log()) (#1345, @IndrajeetPatil). object_usage_linter() gains skip_with argument skip code () expressions. consistent R CMD check, defaults TRUE (#941, #1458, @IndrajeetPatil). Handles backticked symbols inside {glue} expressions correctly, e.g. glue(\"{`x`}\") correctly determines x used (#1619, @MichaelChirico) Detects problems inside R4.1.0+ lambda functions (\\(...)) (#1933, @MichaelChirico) spaces_inside_linter() allows terminal missing keyword arguments (e.g. alist(arg = ); #540, @MichaelChirico) brace_linter() allows empty braced expression line (e.g. (updating_condition()) { }) regardless allow_single_line match corresponding behavior {styler}. expedient style guide handling case awaits clarification: https://github.com/tidyverse/style/issues/191. (#1346, @MichaelChirico) undesirable_function_linter() undesirable_operator_linter() now produce error empty vector undesirable functions operators provided (#1867, @IndrajeetPatil). New linters also included defaults (see “New linters” details): indentation_linter() quotes_linter() unnecessary_concatenation_linter() whitespace_linter() lint_package() also looks files exec/ (#1950, @jmaspons).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-3-1-0","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr 3.1.0","text":"New get_r_string() helper get R-equivalent value string, especially useful R-4-style raw strings. Previously internal lintr helper, now exported facilitate writing custom linters (#1493, @MichaelChirico). object_usage_linter() improves lint metadata detecting undefined infix operators, e.g. %>% := (#1497, @MichaelChirico) unused_import_linter() can detect datasets imported packages longer warns package imported datasets (#1545, @IndrajeetPatil). linter triggers error, lint() provide actionable summary error occurred, particularly useful cases like lint_package() responsible file responsible linter unknown (@MichaelChirico). Typically, linters cause R stop – syntax errors lead error lints, example. Please report failures likely bugs. pipe_continuation_linter() recognizes violations involving native R pipe |> (#1609, @MichaelChirico) paste_linter() also catches usages like paste(rep(\"*\", 10L), collapse = \"\") can written concisely strrep(\"*\", 10L) (#1108, @MichaelChirico) spaces_inside_linter() produces lints spaces inside [[ (#1673, @IndrajeetPatil). sprintf_linter() also applies gettextf() (#1677, @MichaelChirico) Documentation linters contains examples code produce lints (#1492, @IndrajeetPatil). implicit_integer_linter() gains parameter allow_colon skip lints expressions like 1:10 (#1155, @MichaelChirico) infix_spaces_linter() supports native R pipe |> (#1793, @AshesITR) unnecessary_concatenation_linter() (f.k.. unneeded_concatenation_linter()) longer lints c(...) (.e., passing ... function call) allow_single_expression = FALSE (#1696, @MichaelChirico) object_name_linter() gains parameter regexes allow custom naming conventions (#822, #1421, @AshesITR) literal_coercion_linter() reports replacement lint message, e.g. code like .integer(1) suggest using 1L instead, code like .numeric(NA) suggest using NA_real_ instead (#1439, @MichaelChirico) Added format() functions lint lints (#1784, @AshesITR) all_linters() function provides easy way access available linters (#1843, @IndrajeetPatil) missing_argument_linter() allows missing arguments quote() calls (#1889, @IndrajeetPatil). get_source_expressions() correctly extracts indented code chunks R Markdown documents, helps avoid spurious lints related whitespace (#1945, @MichaelChirico). convention taken , within chunk, code anchored relative leftmost non-whitespace column. available_linters() gives priority tags exclude_tags case overlap. particular, means available_linters(tags = \"deprecated\") work return deprecated linters without needing specify exclude_tags (#1959, @MichaelChirico). {lintr} configuration file now searched system’s user configuration path; lintr config filename can also configured explicitly setting environment variable R_LINTR_LINTER_FILE (#460, @klmr) Errors {lintr} configuration file now produce informative error messages (#886, @AshesITR)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-3-1-0","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr 3.1.0","text":"matrix_apply_linter() recommends use dedicated rowSums(), colSums(), colMeans(), rowMeans() apply(., MARGIN, sum) apply(., MARGIN, mean). recommended alternative much efficient readable (#1869, @Bisaloo). unnecessary_lambda_linter(): detect unnecessary lambdas (anonymous functions), e.g. lapply(x, function(xi) sum(xi)) can lapply(x, sum) purrr::map(x, ~quantile(.x, 0.75, na.rm = TRUE)) can purrr::map(x, quantile, 0.75, na.rm = TRUE). Naming probs = 0.75 can improve readability (#1531, #1866, @MichaelChirico, @Bisaloo). redundant_equals_linter() redundant comparisons TRUE FALSE like is_treatment == TRUE (#1500, @MichaelChirico) lengths_linter() encouraging usage lengths(x) instead sapply(x, length) (similar) function_return_linter() handling issues function return() statements. Currently handles assignments within return() clause, e.g. return(x <- foo()) (@MichaelChirico) boolean_arithmetic_linter() identifying places logical aggregations appropriate, e.g. length((x == y)) == 0 !(x == y) even (x != y) (@MichaelChirico) for_loop_index_linter() prevent overwriting local variables loop declared like (x x) { ... } (@MichaelChirico) is_numeric_linter() redundant checks equivalent .numeric(x) .numeric(x) || .integer(x) class(x) %% c(\"numeric\", \"integer\") (@MichaelChirico) empty_assignment_linter() identifying empty assignments like x = {} clearly written x = NULL (@MichaelChirico) unnecessary_placeholder_linter() identifying usage {magrittr} placeholder . omitted (@MichaelChirico) routine_registration_linter() identifying native routines don’t use registration (useDynLib NAMESPACE; @MichaelChirico) indentation_linter() checking indentation conforms 2-space Tidyverse-style (@AshesITR @dgkf, #1411, #1792, #1898). unnecessary_nested_if_linter() checking unnecessary nested statements single statement appropriate conditional expression suffice (@IndrajeetPatil @AshesITR, #1778). implicit_assignment_linter() checking implicit assignments function calls (@IndrajeetPatil @AshesITR, #1777). quotes_linter() generalized version (now deprecated) single_quotes_linter(). accepts argument delimiter specify whether \" ' accepted method delimiting character literals. default, \", reflects Tidyverse style guide recommendation matches behavior single_quotes_linter(). unnecessary_concatenation_linter() simply unneeded_concatenation_linter(), renamed. consecutive_assertion_linter() (f.k.. consecutive_stopifnot_linter()) now lints consecutive calls assertthat::assert_that() (long msg= argument used; #1604, @MichaelChirico). whitespace_linter() simply no_tab_linter(), renamed. future, plan extend work different whitespace preferences.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"notes-3-1-0","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr 3.1.0","text":"{lintr} now depends R version 3.5.0, line tidyverse policy R version compatibility. lint() continues support Rmarkdown documents. users custom .Rmd engines, e.g. marginformat {tufte} theorem {bookdown}, note engines must registered {knitr} prior running lint() order {lintr} behave expected, .e., shown part knitr::knit_engines$get(). {tufte} {bookdown} particular, one needs load package namespace accomplish (.e., minimally loadNamespace(\"tufte\") loadNamespace(\"bookdown\"), respectively, register packages’ custom engines; since library() also runs loadNamespace(), running library() also work). Note {tufte} added code .onLoad() recently request (see https://github.com/rstudio/tufte/issues/117). Therefore, ensure ’re using recent version get behavior described {tufte}. generally, requirement loadNamespace() register package’s custom {knitr} engines, may need work package authors figure solution engines. Thanks Yihui developers helpful discussions around issue (#797, @IndrajeetPatil). output lint() Lint() gain S3 class \"list\" assist S3 dispatch (#1494, @MichaelChirico) corollary, now register as_tibble method class lints, conditional {tibble} availability, avoid dispatching list method work lint() output (#1997, @MichaelChirico) object_usage_linter() gives helpful warning glue() expression fails evaluate (#1985, @MichaelChirico) documentation object_name_linter() now describes \"symbols\" works passed styles parameter (#1924, @hedsnz).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-302","dir":"Changelog","previous_headings":"","what":"lintr 3.0.2","title":"lintr 3.0.2","text":"CRAN release: 2022-10-19 Fix test avoid leaving behind cache files global cache directory.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-301","dir":"Changelog","previous_headings":"","what":"lintr 3.0.1","title":"lintr 3.0.1","text":"CRAN release: 2022-09-13 Skip multi-byte tests non UTF-8 locales (#1504) modify_defaults() longer uses mistaken \"lintr_function\" S3 class, instead applying \"linter\" class also common Linter(). Linter() also includes \"function\" S3 class output facilitate S3 dispatch function methods appropriate (#1392, @MichaelChirico).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"changes-to-defaults-3-0-1","dir":"Changelog","previous_headings":"","what":"Changes to defaults","title":"lintr 3.0.1","text":"brace_linter() allows opening curly braces new line comment ending preceding line (#1433 #1434, @IndrajeetPatil). seq_linter() produces lint seq(...), since also properly handle empty edge cases (#1468, @IndrajeetPatil). seq_linter() additionally lints 1:n() ({dplyr}) 1:.N ({data.table}) (#1396, @IndrajeetPatil). literal_coercion_linter() lints {rlang}’s atomic vector constructors (.e., int(), chr(), lgl(), dbl()) argument scalar (#1437, @IndrajeetPatil). redundant_ifelse_linter()’s lint message correctly suggests negation yes condition 0 (#1432, @IndrajeetPatil). seq_linter() provides specific replacement code lint message (#1475, @IndrajeetPatil).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-and-improved-features-3-0-1","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr 3.0.1","text":"New sort_linter() detect x[order(x)] recommend faster clearer alternative: sort(x) (#1528, @Bisaloo) unreachable_code_linter() ignores trailing comments match closing nolint block (#1347, @AshesITR). New function_argument_linter() enforce arguments defaults appear last function declarations, see Tidyverse design guide (#450, @AshesITR). New allow_trailing argument added assignment_linter() check assignment operators end line, value following line (#1491, @ashbaldry) New sarif_output() function output lints SARIF output (#1424, @shaopeng-gh) commented_code_linter() now lints commented argument code, containing trailing comma, well (#386, @AshesITR). example comment containing # na.rm = TRUE, now triggers lint.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-0-1","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.0.1","text":"object_length_linter() fail case dependencies exports (e.g. data-packages) (#1424, #1509, @IndrajeetPatil). get_source_expressions() longer fails R files match knitr pattern (#743, #879, #1406, @AshesITR). Parse error lints now appear linter name \"error\" instead NA (#1405, @AshesITR). Also, linting longer runs source_expressions contain invalid string data cause error messages linters. linters. Prevent lint() hanging Rmd files syntax errors (#1443, @MichaelChirico). get_source_expressions() longer omits trailing non-code lines knitr files (#1400, #1415, @AshesITR). fixes location information trailing_blank_lines_linter() RMarkdown documents without terminal newlines. vignette(\"lintr\") incorrectly cited exclude key setting file exclusions .lintr actually exclusions. (#1401, @AshesITR) Fixed file exclusion detection lint_dir() longer errors multiple exclusions global exclusions configured single file (#1413, #1442, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"other-changes-3-0-1","dir":"Changelog","previous_headings":"","what":"Other changes","title":"lintr 3.0.1","text":"minimum needed version soft dependency withr bumped 2.5.0 (#1404, @IndrajeetPatil). Changed deprecation warning with_defaults() also mention modify_defaults() (#1438, @AshesITR). Quarto files (.qmd) supported box. documentation testing infrastructure updated reflect (#1486, @IndrajeetPatil).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-300","dir":"Changelog","previous_headings":"","what":"lintr 3.0.0","title":"lintr 3.0.0","text":"CRAN release: 2022-06-13","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"breaking-changes-3-0-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"lintr 3.0.0","text":"linters now function factories (.e., functions return functions) consistency. Previously, linters customizable parameters factories (#245, @fangly, @AshesITR, @MichaelChirico). means usage lint(\"file.R\", seq_linter) updated lint(\"file.R\", seq_linter()), following update custom linters: Exclusions specified .lintr file now relative location file support excluding entire directories (#158, #438, @AshesITR). Removed long-deprecated linters (’ve marked deprecated since v1.0.1 2017): absolute_paths_linter() camel_case_linter() multiple_dots_linter() snake_case_linter() trailing_semicolons_linter() Removed return() all_undesirable_functions early returns (often improve readability reduce code complexity) require explicit use return(). Follow #1100 upcoming return_linter() lint unnecessary return() statements (#1146, @AshesITR). Note can replicate old behavior supplying return custom undesirable function: undesirable_function_linter(c(all_undesirable_functions, list(return = NA)))","code":"my_custom_linter <- function(source_expression) { ... } # becomes my_custom_linter <- function() Linter(function(source_expression) { ... })"},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecations-3-0-0","dir":"Changelog","previous_headings":"","what":"Deprecations","title":"lintr 3.0.0","text":"Lints now marked name linter caused instead name implementation function. Deprecated obsolete linter argument Lint() (#664, #673, #746, @AshesITR). Downstream custom linters follow suit. Renamed semicolon_terminator_linter() semicolon_linter() better consistency. semicolon_terminator_linter() survives marked deprecation. new linter also new signature, taking arguments allow_compound allow_trailing replace old single argument semicolon, signature consistency linters. closed_curly_linter() open_curly_linter() paren_brace_linter() lint(), ... now 3rd argument, earlier cache. lint_dir() lint_package(), ... now 2nd argument, earlier relative_path. Deprecated argument source_file exported functions with_id() ids_with_token(). renamed source_expression better reflect argument typically output get_source_expressions(). now, old argument source_file can still used (warning). now-private functional versions many linters also underwent renaming (source_file -> source_expression). direct effect packages importing lintr, mentioned case custom linters imitating lintr style also adopted source_file naming want adapt keep sync. Deprecated with_defaults() favor linters_with_defaults(), add modify_defaults() intended used generally modify (.e., extend, trim, /update) list defaults. Note argument corresponding with_defaults()’s default= called defaults= (.e., pluralized) , usage like with_defaults(default = NULL, ...) converted linters_with_defaults(defaults = list(), ...) (#1029, #1336, #1361, @AshesITR @michaelchirico). Deprecated find_line() find_column() helpers item-level expressions returned get_source_expressions(). helpers typically associated regex-based logic building linters, rarely needed prone false positives; now lintr almost exclusively uses XPath-based logic linters, longer necessary (#1373, @MichaelChirico).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"updates-to-default_linters-3-0-0","dir":"Changelog","previous_headings":"Other changes to defaults","what":"Updates to default_linters","title":"lintr 3.0.0","text":"closed_curly_linter(); now also allow }] addition }) }, exceptions, .e., } doesn’t need line paired closing square bracket, closing parenthesis, comma. Also improved lint metadata source markers land closing brace instead closing parenthesis improve experience fixing lint (#583, @AshesITR). open_curly_linter(); also longer lint unnecessary trailing whitespace (use trailing_whitespace_linter() ) also allow (, ,, %>% preceding lines exceptions, .e., { can alone line previous line terminated opening parenthesis, comma, pipe (%>%) (#487, #1028, @AshesITR). paren_brace_linter(); brace_linter() also lints /else repeat missing whitespace. Require else come line preceding }, present (#884, @MichaelChirico). Require functions spanning multiple lines use curly braces (#987, @MichaelChirico). Require balanced usage {} /else conditions, .e., branch uses braces, must else branch, vice versa (#983, @MichaelChirico). New paren_body_linter() checks space right parenthesis body expression (#809, @kpagacz). Added semicolon_linter() default enforces tidyverse style guide rule (#683, @AshesITR). Right assignments now linted default (-> ->>). New argument allow_cascading_assign (TRUE default) toggles whether lint <<- ->>. New argument allow_right_assign (FALSE default) toggles whether lint -> ->>. commented_code_linter(): use parse tree find comments, eliminating false positives (#451, @AshesITR). Extended lint x != NA (, == caught) NA == x (, NA RHS caught). Extended skip usages comments like .na(x) # use .na(x), x == NA. function_left_parentheses_linter(): improved location information (#1266, #1267, @AshesITR). Added argument allow_multiple_spaces (TRUE default) toggles whether generate lint operators used multiple spaces, e.g. x + 2. default setting allows extra spacing used increase line--line alignment (#940, @f-ritter @MichaelChirico). Extended usages like ~b function(=1) { ... } linted (#930, #michaelchirico). Added argument exclude_operators disable lints selected infix operators. default, “low-precedence” operators throw lints; see ?infix_spaces_linter enumeration . (#914, @MichaelChirico). Add exception / usage box::use() declarations (#1087, @klmr). line_length_linter(): place source marker margin affected line improve user experience de-linting – just press Return (#735, @AshesITR).* no_tab_linter(): use reliable matching (e.g., excluding matches found comments; #441, @russHyde). object_length_linter(): correctly detect generics count implementation class towards length. prevents false positive lints case long generic names, e.g. very_very_very_long_generic_name.short_class longer produces lint (#871, @AshesITR). Improved generic detection – user-defined method my_method.upstream.class, upstream.class longer throws lint generic (my_method) properly uses snake_case (#737, @AshesITR). Exclude special R namespace hook functions .onLoad() (#500, #614, @AshesITR @MichaelChirico). Correctly detect imported functions linting packages (#642, @AshesITR). Correctly detect assignment generics like names<-.class_name (#843, @jonkeane). \"symbols\" new default style won’t lint -symbol object names. particular, means operator names like %+% allowed. longer lints names used $ extractions (#582, @AshesITR). Detect global variables top-level dollar-assignments (#666, @AshesITR). Report usage warnings spanning multiple lines (#507, @AshesITR). Detect usages inside glue::glue() constructs (#942, @AshesITR). Extended include functions assigned = instead <- (#1081, @MichaelChirico). Detect functions exported packages explicitly attached using library() require() calls (#1127, @AshesITR). Improved location information cases previous regex-based approach didn’t work, e.g. unicode characters variable names (#1285, @AshesITR). Correctly detect functions declared within assign() setMethod() (#1322, @AshesITR). spaces_inside_linter(): ignore spaces preceding trailing comments (#636, @MichaelChirico). Added default enforces tidyverse style guide rule (#517, @AshesITR). longer lint occurrences T F used subsetting, give better message used variable names (#657, @AshesITR). Extended lint files without terminal newline (#675, @AshesITR). Also, running lint() file without terminal newline longer throws warning(). Extended also lint completely blank lines default (#1044, @AshesITR). Added argument allow_empty_lines (FALSE default) toggle behavior. Improved trailing whitespace inside string literals trigger lint (#1045, @AshesITR). Added argument allow_in_strings (TRUE default) toggle behavior. browser() debug() debugcall() debugonce() trace() untrace() longer lints library() require() calls attaching package undesired name, e.g. library(foo) (#814, @kpagacz @MichaelChirico). longer lints undesirable symbols used names $ extractions (#1050, @AshesITR). Added explanation certain functions might undesirable alternatives use; ditto undesirable_operator_linter() (#1133, #1146, #1159, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"other-noteworthy-changes-3-0-0","dir":"Changelog","previous_headings":"Other changes to defaults","what":"Other noteworthy changes","title":"lintr 3.0.0","text":"cyclocomp_linter(): set default complexity_limit 15. brings default sync enforced via default_linters (#693, @AshesITR). lint_package() now lints files demo directory default (#703, @dmurdoch). Moved default lintr cache directory ~/.R/lintr_cache (violation CRAN policy) R_user_dir(\"lintr\", \"cache\"). Note 3.0.0 major version update invalidates old cache anyway, can safely deleted (#1062, @AshesITR).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-3-0-0","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr 3.0.0","text":"backport_linter() detecting mismatched R version dependencies (#506, #1316, #1318, #1319, @MichaelChirico @AshesITR). duplicate_argument_linter() similarly checks duplicate arguments supplied function calls (#850, @renkun-ken). missing_argument_linter() check empty (missing) arguments function calls (#563, #1152, @renkun-ken @AshesITR). missing_package_linter() check packages calls library() friends missing (#536, #1037, @renkun-ken @MichaelChirico). namespace_linter() check common mistakes pkg::symbol usages (#548, @renkun-ken). package_hooks_linter() run series checks also done R CMD check .onLoad(), .onAttach(), .Last.lib() .onDetach() hooks (#882, @MichaelChirico). pipe_call_linter() enforce steps magrittr pipelines use explicit calls instead symbols, e.g. x %>% mean() instead x %>% mean (#801, @MichaelChirico). sprintf_linter() check common mistakes sprintf() usage (#544, #624, @renkun-ken @AshesITR). unused_import_linter() detect unnecessary library() calls R scripts (#239, @jimhester, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"google-linters-3-0-0","dir":"Changelog","previous_headings":"New and improved features > New linters","what":"Google linters","title":"lintr 3.0.0","text":"Google heavy user lintr internally, developed large set linters improving code consistency correcting common R usage mistakes. release includes many linters general interest broader R community. included future releases. See, e.g. #884, #979, #998, #1011, #1016, #1036, #1051, #1066, #1067; special thanks @MichaelChirico @michaelquinn32. any_duplicated_linter() Require usage anyDuplicated(x) > 0L (duplicated(x)) similar. any_is_na_linter() Require usage anyNA(x) (.na(x)). class_equals_linter() Prevent comparing class(x) ==, !=, %%, inherits() typically preferred. condition_message_linter() Prevent condition messages constructed like stop(paste(...)) (just stop(...) preferable). conjunct_test_linter() Require usage expect_true(x); expect_true(y) expect_true(x && y) similar. consecutive_stopifnot_linter() Require consecutive calls stopifnot() unified one. expect_comparison_linter() Require usage expect_gt(x, y) expect_true(x > y) similar. expect_identical_linter() Require usage expect_identical() default, expect_equal() exception. expect_length_linter() Require usage expect_length(x, n) expect_equal(length(x), n) similar. expect_named_linter() Require usage expect_named(x, n) expect_equal(names(x), n) similar. expect_not_linter() Require usage expect_false(x) expect_true(!x), vice versa. expect_null_linter() Require usage expect_null(x) expect_equal(x, NULL) similar. expect_s3_class_linter() Require usage expect_s3_class(x, k) expect_equal(class(x), k) similar. expect_s4_class_linter() Require usage expect_s4_class(x, k) expect_true(methods::(x, k)). expect_true_false_linter() Require usage expect_true(x) expect_equal(x, TRUE) similar. expect_type_linter() Require usage expect_type(x, t) expect_equal(typeof(x), t) similar. Added parameter allow_grepl (default FALSE) toggle whether grepl() usages linted. might treated separately grepl(\"^x\", NA) FALSE; startsWith() equivalent get FALSE missing input clunkier, explicit: !.na(x) & startsWith(x, string) (#1376, @MichaelChirico). ifelse_censor_linter() Require usage pmax() / pmin() appropriate, e.g. ifelse(x > y, x, y) pmax(x, y). inner_combine_linter() Require inputs known-vectorized functions combined first rather later, e.g. .Date(c(x, y)) c(.Date(x), .Date(y)). literal_coercion_linter() Require using correctly-typed literals instead direct coercion, e.g. 1L instead .numeric(1). nested_ifelse_linter() Prevent nested calls ifelse() like ifelse(, x, ifelse(B, y, z)), similar. numeric_leading_zero_linter() Require leading 0 fractional numeric constants, e.g. 0.1 instead .1. outer_negation_linter() Require usage !(x) (!x) !(x) (!x). paste0() encouraged instead paste(sep = \"\"). toString() glue::glue_collapse() encouraged instead paste(x, collapse = \", \"). Lint sep= passed paste0() – typically mistake. redundant_ifelse_linter() Prevent usage like ifelse(& B, TRUE, FALSE) ifelse(C, 0, 1) (latter .numeric(!C)). regex_subset_linter() Require usage grep(ptn, x, value = TRUE) x[grep(ptn, x)] similar. string_boundary_linter() Require usage startsWith(x, ptn) grepl(\"^ptn\", x) substr(x, 1, 3) == ptn similar. strings_as_factors_linter() Check code designed work stringsAsFactors = FALSE default change R 4.0 examining code data.frame() usages susceptible assumptions default value stringsAsFactors=. system_file_linter() Prevent usage like file.path(system.file(\"\", package = \"pkg\"), \"B\") simply system.file(\"\", \"B\", package = \"pkg\") concise readable. unreachable_code_linter() Prevent code return() stop() statements never reached (extended #1051 thanks early user testing, thanks @bersbersbers!). vector_logic_linter() Require use scalar logical operators (&& ||) inside () conditions similar. yoda_test_linter() Require usage expect_identical(x, 1L) expect_equal(1L, x) similar.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"other-features-and-improvements-3-0-0","dir":"Changelog","previous_headings":"New and improved features","what":"Other features and improvements","title":"lintr 3.0.0","text":"linter help page. ?linters also links tag help pages, collecting linters similar goal. linter can multiple tags. available_linters(): new function list available linters tags. feature extensible package authors providing add-linters {lintr}. available_tags(): new function list available tags. linters_with_tags(): new function help build list linters using tags. Encodings: lintr now supports non-system character Encodings. correct encoding auto-detected .Rproj DESCRIPTION files project. Override default encoding setting lintr (#752, #782, @AshesITR). Jenkins CI: Support writing comments GitHub repo running Jenkins CI (#488, @fdlk). Performance: Optimized performance-critical functions lintr, get_source_expressions() resulting 2x speedup test suite even complex files (#1169, #1197, #1200, #1201, #1214, @MichaelChirico @AshesITR). Average lint_package() execution time 30% median package sees 40% improvement. Raw strings: Several linters tightened internal logic allow raw strings like R\"( \\string )\" (#1034, #1285, @MichaelChirico @AshesITR). Added linter name lintrs output facilitate discovery correct name (#1357, @AshesITR). Improved S3 generic detection non-standard S3 generics UseMethod() called several preceding expressions (#846, @jonkeane). extraction_operator_linter(): longer lint x[NULL] (#1273, @AshesITR). is_lint_level(): new exported helper readably explaining type expression required custom linter. linters written require full file’s parse tree (example, single_quotes_linter()). Others need single expressions, cache-friendly (linters written way leverage caching) (#921, @MichaelChirico). lint_dir() excludes renv packrat directories default (#697, @AshesITR). lint(): new optional argument text supplying line lines directly, e.g. file already memory linting done ad hoc (#503, @renkun-ken). seq_linter(): improve lint message clearer reason linting (#522, @MichaelChirico). Correctly considers arguments pipelines (%>% |>; #573, #1270, @michaelquinn32 @AshesITR). New argument allow_single_expression, default TRUE, toggling whether c(x) linted, .e., call c() one entry constant. cases, c() can simply dropped, e.g. c(:b); others, parentheses still needed, e.g. -c(:b) -(:b); still others, c() used side-effect stripping attributes, e.g. c(factor(letters)) c(matrix(1:10, 5, 2)). last case, c() can () cases replaced .vector() .integer() readability. fact, suspect always preferable , may change default allow_single_expression = FALSE future. Please report use case .vector() suit needs (#1344, @MichaelChirico). use_lintr(): new exported helper creating minimal .lintr configuration (#902, @AshesITR). xml_nodes_to_lints(): new exported helper converting xml_node objects obtained using linter logic expressed XPath Lint objects (#1124, #1216, #1234, @MichaelChirico @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"bug-fixes-3-0-0","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr 3.0.0","text":"RStudio: Source markers cleared lints (#520, @AshesITR). Error message mismatched starts ends exclusion ranges now helpful. (#571, #860, @AshesITR @danielinteractive). Improved location information R parse errors (#894, #892, @renkun-ken @AshesITR). Fix possible error invalid XML produced xmlparsedata::xml_parse_data() (#559, @renkun-ken). Fix handling zero-length variable name error (#566, @renkun-ken). Malformed Rmd files now cause lint instead error (#571, @AshesITR). longer fails getParseData() returns truncated (invalid) Unicode character parsed text (#815, @leogama). Fixes text value STR_CONST nodes involving 1- 2-width octal escapes (e.g. \"\\1\") account R parser bug (https://bugs.r-project.org/show_bug.cgi?id=18323; #1056, @MichaelChirico). Handle Rmd inputs containing unevaluated code blocks named format specifiers (#472, @russHyde). line_length_linter(): fix bug causing duplicate lints lines containing multiple expressions (#681, @AshesITR). Warns returns NULL package found (instead giving peculiar error message; #776, @MichaelChirico). Stricter considered package – folders named DESCRIPTION ignored (#702, @MichaelChirico). longer duplicates lintr_function class already present (#511, @AshesITR). Warns named argument NULL name defaults (#1049, @AshesITR). linters_with_defaults() handles automatic naming long arguments correctly (#774, @MichaelChirico). save_cache() now recursively create cache directory; avoids errors arise parent directories exist (#60, @dankessler). spaces_left_parentheses_linter(): fix bug causing warnings like “parent == parent[before_operator_idx] longer object length multiple shorter object length” nested expressions (#654, @AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"internals-3-0-0","dir":"Changelog","previous_headings":"","what":"Internals","title":"lintr 3.0.0","text":"Added new, restrictive test workflow - test-package - fails warnings emitted tests (#1263, #1272, @AshesITR). Added secondary, restrictive lint workflow - lint-changed-files - newly written / modified code (#641, @dragosmg). Several optional Imported packages become Suggested dependencies: httr, testthat, rstudioapi. allow snappier CI builds usages relying “peripheral” features package. Special thanks @bersbersbers early testing 3.0.0 changes. Switched CI Travis GitHub Actions, using full tidyverse recommended R CMD check. Code coverage linting implemented using separate GitHub Actions workflows (#572, @dragosmg). Updated R CMD GitHub Actions workflow check R 3.6 Ubuntu, instead R 3.3, R 4.0 Windows, instead R 3.6 (#803, @ dragosmg). lintr now uses 3rd edition testthat (@MichaelChirico, @AshesITR, #910, #967).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-201","dir":"Changelog","previous_headings":"","what":"lintr 2.0.1","title":"lintr 2.0.1","text":"CRAN release: 2020-02-19","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-features-2-0-1","dir":"Changelog","previous_headings":"","what":"New features","title":"lintr 2.0.1","text":"lintr now supports GitHub Actions print lints warning messages lints printed action. lint_package() now lint vignettes data-raw default (#447, @AshesITR). lint_dir() now include Rmd Rnw files default (@AshesITR).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"minor-fixes-and-features-2-0-1","dir":"Changelog","previous_headings":"","what":"Minor fixes and features","title":"lintr 2.0.1","text":"single_quote_linter() longer causes print issue open quote appears column > close quote (#457, @jamieRowen) absolute_path_linter() nonportable_path_linter() now handle file-paths wrapped double-quotes (#433, #437, @russHyde). get_source_expressions() changed handle expr_or_assign_or_help tokens arising parsing code containing equals-assignments R-devel (#403, #456, @russHyde). object_usage_linter changed ensure lint-position indicated relative start file, rather start defining function (#432, @russHyde). commas_linter now allows spaces come comma used denote fall-switch statement (#499, @MrMallIronmaker)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-200","dir":"Changelog","previous_headings":"","what":"lintr 2.0.0","title":"lintr 2.0.0","text":"CRAN release: 2019-10-01 lintr 2.0.0 major release, incorporates development changes since last major release (1.0.0) 2016-04-16.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"deprecated-functions-2-0-0","dir":"Changelog","previous_headings":"","what":"Deprecated functions","title":"lintr 2.0.0","text":"Deprecated camel_case_linter(), snake_case_linter() multiple_dots_linter() favor object_name_linter() enforce given style: snake_case, dotted.case, lowerCamelCalse, UpperCamelCase, alllowercase ALLUPPERCASE (#59, @fangly). Deprecated absolute_paths_linter() favor new absolute_path_linter(), lax mode fewer false positive lints (#199, @fangly).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-linters-2-0-0","dir":"Changelog","previous_headings":"","what":"New linters","title":"lintr 2.0.0","text":"New cyclocomp_linter() identifies overly complex functions (#361, @fabian-s) New equals_na_linter() (#143, #326, @jabranham) New extraction_operator_linter() checks [[ operator used extracting single element object, [ (subsetting) $ (interactive use) (@fangly). New function_left_parentheses_linter() check space function name left parentheses (#204, @jrnold). New implicit_integer_linter() detects round numbers declared integers, .e. 1 instead 1L (@fangly). New nonportable_path_linter() identifies paths constructed without file.path() (@fangly). New paren_brace_linter() checks space right parenthesis opening curly brace (@bfgray3, #242). New pipe_continuation_linter() ensure space %>% newline afterwards (#216). expressions (#181, @fangly). New seq_linter(), finds 1:length(...) (similar) expressions (#155, 1) New todo_comment_linter() lints TODOs (@fangly). New T_and_F_symbol_linter() warns using T F instead TRUE FALSE (@fangly). New undesirable_operator_linter() undesirable_function_linter() lint uses user-specified functions operators (#48, #149, @fangly). New unneeded_concatenation_linter() lints uses c() constant arguments (@fangly).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-functions-for-writing-linters-2-0-0","dir":"Changelog","previous_headings":"","what":"New functions for writing linters","title":"lintr 2.0.0","text":"Export expect_lint() (#178, #210) Export ids_with_token() with_id() (#297 @stufield) linters can use XML parse tree well now, via https://github.com/MangoTheCat/xmlparsedata package (#154, 1)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"new-functions-for-users-2-0-0","dir":"Changelog","previous_headings":"","what":"New functions for users","title":"lintr 2.0.0","text":"New lint_dir() function lint files given directory (@arekbee, #360) New summary.lints() function summarize linter results (#260, #262, @wlandau). New checkstyle_output() function output lints checkstyle XML output (#156, @joshkgold)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"linter-fixes-2-0-0","dir":"Changelog","previous_headings":"","what":"Linter fixes","title":"lintr 2.0.0","text":"closed_curly_linter() now allows closing parenthesis comma closing curly brace (#167, @Enchufa2) commas_linter() now handles missing arguments calls properly (#145) commented_code_linter() now relaxed, longer lints comments within roxygen blocks consider “-” R operator avoid many false positives. function_left_parentheses_linter() now allows spaces function starts left parenthesis (#311) no_tab_linter() now reports proper line cases (#134, @fangly) object_length_linter() argument length now defaults 30 consistency (#325 @DragosMG) object_name_linter() now works passed multiple styles (#341, @infotroph) object_usage_linter() changed better detect lexical scoping global variables (#27, #336, #91, #382) object_usage_linter() now respects utils::globalVariables(), can used avoid false positive warnings due non-standard evaluation (#352) object_usage_linter() now ignores top level calls contain function definitions (#26). object_linter*()s now lint objects declared current file (#76, #108, #136, #191, #194, #201, @fangly). open_curly_linter() closed_curly_linter() now lint double curly syntax (#388) open_curly_linter() now allows comments curly braces (#188) pipe_continuation_linter() now behaves better nested expressions, functions etc. (#366 @russHyde) space_inside_linter() now reports proper line column numbers (#203, @fangly)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"general-improvements-and-fixes-2-0-0","dir":"Changelog","previous_headings":"","what":"General improvements and fixes","title":"lintr 2.0.0","text":"expect_lint() now longer shows Rstudio markers error messages correctly preserved (#180, #211, @fangly) Lint() / .data.frame() error now fixed (#179, @fangly). lint() longer errors inline \\\\Sexpr (#127). lint() longer errors ‘<% %>’ constructs (#185). lint_package() now works cache, intended (#146, @schloerke) lint_package() now excludes R/RcppExports.R default (#282) lint_package() now removes fully excluded files soon possible lintr now looks configuration parent directories well package directory (#238, #345) seq_linter now one default linters (#316). Fix issue lintr’s compatibility R-devel, due new version PCRE library (#411.) read_settings() now better error message config file end newline (#160, #189) expect_lint_free() now automatically skipped run covr (#287) Now lintr tries generate comments running wercker travis CI (#166) Add support overriding GitHub API Token via GITHUB_TOKEN environment variable (#63, @mattyb) Config files now also searched users’ home directory (#266, @randy3k) Fixed crash caused ambiguous cache file paths (#212, @fangly). RStudio addins lint current source project (fixes #264, @JhossePaul) Added proper handling tab characters (fixes #44, @fangly) lintr need igraph package (#152, 1) Fixed cache saved directory requested (#213, @fangly) avoid reading pre-processing ignored files (@mwaldstein) Allow number # start comment. Useful ESS (#299, @prosoitos) R Markdown files contain chunks longer treated code (#370). Fixed plain-code-block bug Rmarkdown (#252, @russHyde) Fixed bug non-R chunks using {lang} engine format parsed R-markdown (#322, @russHyde) Ensured lintr runs / installs / tests R-3.6: pinned github xmlparsedata; ensure vectors length-1 compared using && || (#363 #377 #384 #391, @russHyde).","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-103","dir":"Changelog","previous_headings":"","what":"lintr 1.0.3","title":"lintr 1.0.3","text":"CRAN release: 2018-11-08 Fix tests work changes parser R 3.6","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-102","dir":"Changelog","previous_headings":"","what":"lintr 1.0.2","title":"lintr 1.0.2","text":"CRAN release: 2017-11-08 Fix tests work upcoming testthat release.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-101","dir":"Changelog","previous_headings":"","what":"lintr 1.0.1","title":"lintr 1.0.1","text":"CRAN release: 2017-08-10 bugfix work knitr 1.16.7 expect_lint_free() now always skipped CRAN. necessary non-binary R source may available running tests CRAN, tests may run package directory.","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-100","dir":"Changelog","previous_headings":"","what":"lintr 1.0.0","title":"lintr 1.0.0","text":"CRAN release: 2016-04-16 bugfix work testthat 1.0.0","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-033","dir":"Changelog","previous_headings":"","what":"lintr 0.3.3","title":"lintr 0.3.3","text":"CRAN release: 2015-09-15 infix_spaces_linter now properly checks = named arguments. (#130, @saurfang). commas_linter now properly recognizes lints preceded blank line points missing space rather comma (#111, #129, @saurfang). Make spaces_left_parentheses_linter robust determining ( type (#128, @saurfang) commented_code_linter (#83, @jackwasey) Now trims long comments (#55, reported @paulstaab) Automatic commenting Github commits pull requests linting Travis-CI expect_lint_free expectation can added testthat unit tests. Robust configuration system exclusion logic Emacs Sublime Text 3 plugins now available respective package repositories. add names.lints, split.lints (#49, @ttriche) Fixed bug caused vim syntastic plugin work properly windows (#46, @abossenbroek) allow lintr customization per project using .lintr config files. use globalenv() instead baseenv() default parent environment methods included. check object usage eval fails. Fixes (#24, reported @fabian-s) trailing_whitespace_linter reporting incorrect line number Use RStudio source marker API display lints (#37, @jjallaire) Permit single quotes quote literal double quotes (#28, @jackwasey) # nolint comments respected caching (#68, @krlmlr) Properly handle knitr document formats Allow (( linting (#259, @nathaneastwood) Remove ^ infix spaces conform tidyverse. (#302, @nathaneastwood)","code":""},{"path":"https://lintr.r-lib.org/dev/news/index.html","id":"lintr-020","dir":"Changelog","previous_headings":"","what":"lintr 0.2.0","title":"lintr 0.2.0","text":"CRAN release: 2014-12-01 Initial release","code":""}]