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

lintr maintainers

-

2023-07-01

+

2023-07-02

Source: vignettes/creating_linters.Rmd
creating_linters.Rmd
diff --git a/dev/articles/lintr.html b/dev/articles/lintr.html index 37ed5398e..be3f41978 100644 --- a/dev/articles/lintr.html +++ b/dev/articles/lintr.html @@ -609,15 +609,15 @@

Advanced: programmatic retri print(as.data.frame(lint(tmp, linters = eval(call(linter_name))))) }) #> filename line_number column_number type -#> 1 /tmp/Rtmpb4PWSY/file1e8045288825 1 3 style +#> 1 /tmp/Rtmp9oQt7d/file1e0964c795c9 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 get #> filename line_number column_number type -#> 1 /tmp/Rtmpb4PWSY/file1e8045288825 1 3 style +#> 1 /tmp/Rtmp9oQt7d/file1e0964c795c9 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter #> filename line_number column_number type -#> 1 /tmp/Rtmpb4PWSY/file1e8045288825 1 3 style +#> 1 /tmp/Rtmp9oQt7d/file1e0964c795c9 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter diff --git a/dev/news/index.html b/dev/news/index.html index 350c226b3..20eea229d 100644 --- a/dev/news/index.html +++ b/dev/news/index.html @@ -105,7 +105,11 @@

Bug fixeslinters_with_defaults() no longer erroneously marks linter factories as linters (#1725, @AshesITR).

  • Row names for available_linters() data frame are now contiguous (#1781, @IndrajeetPatil).

  • object_name_linter() allows all S3 group Generics (see ?base::groupGeneric) and S3 generics defined in a different file in the same package (#1808, #1841, @AshesITR)

  • -
  • object_usage_linter() improves identification of the exact source of a lint for undefined variables in expressions with where the variable is used as a symbol in a usual way, for example in a formula or in an extraction with $ (#1914, @MichaelChirico).

  • +
  • +

    object_usage_linter() improves identification of the exact source of a lint

    +
  • function_left_parentheses_linter() produces a more specific lint (and no longer fails) when the opening parenthesis is on a different line than function or the call name (#1953, @MichaelChirico). Thanks also to @IndrajeetPatil and @lorenzwalthert for identifying a regression in the initial fix, #1963.

  • diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index 188afaeb9..19e2541d1 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: 2023-07-01T17:40Z +last_built: 2023-07-02T06:48Z urls: reference: https://lintr.r-lib.org/reference article: https://lintr.r-lib.org/articles diff --git a/dev/reference/get_r_string.html b/dev/reference/get_r_string.html index 9082b153a..242c3969e 100644 --- a/dev/reference/get_r_string.html +++ b/dev/reference/get_r_string.html @@ -106,7 +106,7 @@

    ArgumentsExamples

    tmp <- withr::local_tempfile(lines = "c('a', 'b')")
     expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f764203756': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file16835ad243f2': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     writeLines(as.character(expr_as_xml))
     #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found
    @@ -118,7 +118,7 @@ 

    Examples# more importantly, extract strings under R>=4 raw strings tmp4.0 <- withr::local_tempfile(lines = "c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')") expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f713afd569': No such file or directory +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file16838231738': No such file or directory #> Error in file(con, "r"): cannot open the connection writeLines(as.character(expr_as_xml4.0)) #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found diff --git a/dev/reference/get_source_expressions.html b/dev/reference/get_source_expressions.html index c1225439d..1ba9f25ce 100644 --- a/dev/reference/get_source_expressions.html +++ b/dev/reference/get_source_expressions.html @@ -134,7 +134,7 @@

    DetailsExamples

    tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
     get_source_expressions(tmp)
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f776b32b96': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683747826eb': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     
    diff --git a/dev/reference/ids_with_token.html b/dev/reference/ids_with_token.html index 327530752..15fe698d6 100644 --- a/dev/reference/ids_with_token.html +++ b/dev/reference/ids_with_token.html @@ -126,7 +126,7 @@

    FunctionsExamples

    tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
     source_exprs <- get_source_expressions(tmp)
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f76e4dd239': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683130a6da9': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     ids_with_token(source_exprs$expressions[[1L]], value = "SYMBOL")
     #> Error in eval(expr, envir, enclos): object 'source_exprs' not found
    diff --git a/dev/reference/is_lint_level.html b/dev/reference/is_lint_level.html
    index b3a139e0c..2c7152bdb 100644
    --- a/dev/reference/is_lint_level.html
    +++ b/dev/reference/is_lint_level.html
    @@ -92,7 +92,7 @@ 

    ArgumentsExamples

    tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
     source_exprs <- get_source_expressions(tmp)
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f7cb70d60': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683447e2f1c': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     is_lint_level(source_exprs$expressions[[1L]], level = "expression")
     #> Error in eval(expr, envir, enclos): object 'source_exprs' not found
    diff --git a/dev/reference/lint.html b/dev/reference/lint.html
    index 7cf670bb2..007defa43 100644
    --- a/dev/reference/lint.html
    +++ b/dev/reference/lint.html
    @@ -183,7 +183,7 @@ 

    DetailsExamples

    f <- withr::local_tempfile(lines = "a=1", fileext = "R")
     lint(f)                # linting a file
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f743768017R': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file16831c097810R': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     lint("a = 123\n")      # linting inline-code
     #> ::warning file=<text>,line=1,col=3::file=<text>,line=1,col=3,[assignment_linter] Use <-, not =, for assignment.
    diff --git a/dev/reference/linters_with_defaults.html b/dev/reference/linters_with_defaults.html
    index aba001b3b..429dc8d1b 100644
    --- a/dev/reference/linters_with_defaults.html
    +++ b/dev/reference/linters_with_defaults.html
    @@ -106,7 +106,7 @@ 

    Examples
    # When using interactively you will usually pass the result onto `lint` or `lint_package()`
     f <- withr::local_tempfile(lines = "my_slightly_long_variable_name <- 2.3", fileext = "R")
     lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120)))
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f736907d5fR': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file168355fa7765R': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     
     # the default linter list with a different line length cutoff
    diff --git a/dev/reference/trailing_blank_lines_linter.html b/dev/reference/trailing_blank_lines_linter.html
    index 9f0c230a4..bfab6e828 100644
    --- a/dev/reference/trailing_blank_lines_linter.html
    +++ b/dev/reference/trailing_blank_lines_linter.html
    @@ -85,25 +85,25 @@ 

    Examples
    # will produce lints
     f <- withr::local_tempfile(lines = "x <- 1\n")
     readLines(f)
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f77a53bae0': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file16832490bb5a': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     lint(
       filename = f,
       linters = trailing_blank_lines_linter()
     )
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f77a53bae0': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file16832490bb5a': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     
     # okay
     f <- withr::local_tempfile(lines = "x <- 1")
     readLines(f)
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f74e77bb3d': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683713a8442': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     lint(
       filename = f,
       linters = trailing_blank_lines_linter()
     )
    -#> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f74e77bb3d': No such file or directory
    +#> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683713a8442': No such file or directory
     #> Error in file(con, "r"): cannot open the connection
     

    diff --git a/dev/search.json b/dev/search.json index 50bede4ed..1b57e7f2f 100644 --- a/dev/search.json +++ b/dev/search.json @@ -1 +1 @@ -[{"path":[]},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement james.f.hester@gmail.com. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with lintr","title":"Getting help with lintr","text":"Thanks using lintr. filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"making-a-reproducible-example","dir":"","previous_headings":"","what":"Making a reproducible example","title":"Getting help with lintr","text":"Start making minimal reproducible example using reprex package. use reprex effectivly, check Get help! section tidyverse site. useful function create reprexes lintr issues lint(). can include code doesn’t lint expected linter question. example, code question contains characters need escaped, consider using raw strings instead save headache figuring multiple levels escapes.","code":"library(lintr) lint( text = \"x = 1\", linters = assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"asking-for-help","dir":"","previous_headings":"","what":"Asking for help","title":"Getting help with lintr","text":"Armed reprex, next step figure ask. ’s clarification question (e.g. don’t know exclude certain files lint workflow), start community.rstudio.com, /StackOverflow. people answer questions.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"filing-an-issue","dir":"","previous_headings":"","what":"Filing an issue","title":"Getting help with lintr","text":"’s bug, can create issue reprex. ’s false positive false negative lint, can either create issue reprex lintr repository, discuss underlying style guide respective repository. opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed. Thanks help!","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions","dir":"Articles","previous_headings":"For packages","what":"GitHub Actions","title":"Continuous integration","text":"package GitHub, easiest way GitHub Actions. workflow configuration files use YAML syntax. usethis package great functionality can help workflow files. straightforward way add lintr workflow package use r-lib/actions’s lint example. usethis, need call create workflow file called lint.yaml place correct location, namely .github/workflows directory repository. file configures steps required run lintr::lint_package() package. Alternatively can use eponymous lint-changed-files.yaml lint changed files: Comments commit pull request printed annotations along side status check GitHub. want builds produce error instead just warning, can set environment variable LINTR_ERROR_ON_LINT=true. set default r-lib/actions’s lint.yaml lint-changed-files.yaml. Note kill R process case lint. project subdirectory like use GitHub Actions annotations, can set options(lintr.github_annotation_project_dir = \"path//project\") make sure annotations point correct paths.","code":"usethis::use_github_action(\"lint\") usethis::use_github_action(\"lint-changed-files\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"travis-ci","dir":"Articles","previous_headings":"For packages","what":"Travis CI","title":"Continuous integration","text":"want run lintr Travis-CI, need Travis install package first. can done adding following line .travis.yml recommend running lintr::lint_package() after_success step build process: lints found commit pull request printed Travis-CI. environment variable LINTR_ERROR_ON_LINT mentioned GitHub actions also works Travis CI builds.","code":"r_github_packages: - r-lib/lintr after_success: - R CMD INSTALL $PKG_TARBALL - Rscript -e 'lintr::lint_package()'"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"for-projects","dir":"Articles","previous_headings":"","what":"For projects","title":"Continuous integration","text":"limited using lintr packages – can use combination continuous integration project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions-1","dir":"Articles","previous_headings":"For projects","what":"GitHub Actions","title":"Continuous integration","text":"project GitHub, take advantage GitHub Actions usethis functionality. r-lib/actions includes lint-project example, can use calling:","code":"usethis::use_github_action(\"lint-project\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"super-linter","dir":"Articles","previous_headings":"For projects","what":"Super-Linter","title":"Continuous integration","text":"lintr powers R lints Super-Linter MegaLinter, provide unified linting experience across many languages. Specifically, execute lintr::lint() R R Markdown files included given project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-the-linter","dir":"Articles","previous_headings":"","what":"Writing the linter","title":"Creating new linters","text":"Describe linter, giving title briefly covering usages discouraged linter active. lines (1) generate Tags section documentation linter1; (2) link full table available linters; (3) mark function export. unfamiliar probably (1), can skipped outside lintr . Next, define name new linter. convention suffix linter names _linter. _linter functions function factories return closure actual linting function. define additional parameters useful linter function declaration (see, e.g. assignment_linter), pipe_call_linter requires additional arguments. core linter logic. xpath XPath expression expressions matching discouraged usage. xpath saved inside factory code (opposed inside linter ) efficiency. Often, xpath somewhat complicated / involve assembly code using paste() glue::glue()[^See infix_spaces_linter() example ], case preferable execute code creating linter; cached XPath re-used expression file linter run. Let’s examine XPath bit closely: Taken together, means want match expr nodes preceded %>% infix operator whose first child node name. maps pretty closely description pipe_call_linter looking , subtlety mapping R code ’re used show XML representation. expr nodes particular take practice get accustomed – use plentiful XPath-based linters lintr guide get extra practice2. Note: xml2 implements XPath 1.0, lacks helpful features available XPath 2.0. closure. called source_expression variable contains top level expressions file linted. call Linter() gives closure class ‘linter’ (also guesses name linter; see ?Linter details). raw text expression available source_file$content. However, generally possible implement linters raw text – consider equals_na_linter. just look == NA text file, ’ll generate many false positives, e.g. comments (# note: .na() proper way check == NA) inside character literals (warning(\"use == NA check missingness\")). ’re also likely generate false negatives, example == NA appear different lines! Working around issues using un-parsed text every situation amounts re-implementing parser. Therefore recommended work tokens source_file$parsed_content source_file$xml_parsed_content, tokenized R parser. tokens obtained parse() utils::getParseData() calls done prior calling new linter. getParseData() returns data.frame information source parse tree file linted. list tokens available r-source/src/main/gram.y. source_file$xml_parsed_content uses xmlparsedata::xml_parse_data() convert getParseData() output XML tree, enables writing linter logic XPath, powerful language expressing paths within nested XML data structure. linters lintr built using XPath powerful language computation abstract syntax tree / parse tree. , return early source_expression expression-level object. get_source_expression() returns object parses input file two ways – done expression--expression, contains expressions file. done facilitate caching. Suppose package long source file (e.g., 100s expressions) – rather run linters every expression every time file updated, caching activated lintr run linter expressions changed. Therefore, preferable write expression-level linters whenever possible. Two types exceptions observed lintr (1) several expressions required ensure linter logic applies (e.g., conjunct_test_linter looks consecutive calls stopifnot(), typically appear consecutive expressions) (2) linter logic simple & fast compute, overhead re-running linter low (e.g., single_quotes_linter). cases, use is_lint_level(source_expression, \"file\"). source_expression$xml_parsed_content copied local variable (strictly necessary facilitates debugging). xml2::xml_find_all() used execute XPath particular expression. Keep mind typically possible single expression generate one lint – example, x %>% na.omit %>% sum trigger pipe_call_linter() twice3. Finally, pass matching XML node(s) xml_nodes_to_lints(), returns Lint objects corresponding “bad” usages found source_expression. See ?Lint ?xml_nodes_to_lints details arguments. Note , message lint always , many linters, message customized closely match observed usage. cases, xml_nodes_to_lint() can conveniently accept function lint_message takes node input converts customized message. See, example, seq_linter.","code":"#' Pipe call linter #' #' Force explicit calls in magrittr pipes, e.g., #' `1:3 %>% sum()` instead of `1:3 %>% sum`. #' @evalRd rd_tags(\"pipe_call_linter\") #' @seealso [linters] for a complete list of linters available in lintr. #' @export pipe_call_linter <- function() { xpath <- \"//expr[preceding-sibling::SPECIAL[text() = '%>%'] and *[1][self::SYMBOL]]\" //expr # global search (//) for 'expr' nodes (R expressions), at any nesting level [ # node[...] looks for any 'node' satisfying conditions in ... preceding-sibling:: # \"siblings\" are at the same nesting level in XML SPECIAL[ # 'SPECIAL' is the parse token for infix operators like %% or %+% text() = '%>%' # text() returns the string associated with this node ] # and # combine conditions with 'and' * # match any node [1] # match the first such node [self::SYMBOL] # match if the current node is a 'SYMBOL' (i.e., a 'name' in R) ] # Linter(function(source_expression) { if (!is_lint_level(source_expression, \"expression\")) { return(list()) } xml <- source_expression$xml_parsed_content bad_expr <- xml2::xml_find_all(xml, xpath) xml_nodes_to_lints( bad_expr, source_expression = source_expression, lint_message = \"Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`.\", type = \"warning\" )"},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-linter-tests","dir":"Articles","previous_headings":"","what":"Writing linter tests","title":"Creating new linters","text":"(NB: section uses assignment_linter() simpler examples pipe_continuation_linter().) lintr works best inside testthat unit testing framework, particular, lintr exports lintr::expect_lint() designed companion testthat expectations. can define tests inside separate test_that calls. linters use default form. test series expectations linter using expect_lint. Please see ?expect_lint full description parameters. main three aspects test : Linter returns lints nothing lint, e.g. Linter returns lint something lint, e.g. many edge cases can think might break , e.g. may want test additional lint attributes correct, type, line number, column number, e.g. Finally, good idea test linter reports multiple lints needed, e.g. always better write many tests rather .","code":"test_that(\"returns the correct linting\", { expect_lint(\"blah\", NULL, assignment_linter()) expect_lint(\"blah=1\", rex(\"Use <-, not =, for assignment.\"), assignment_linter() ) expect_lint(\"fun((blah = fun(1)))\", rex(\"Use <-, not =, for assignment.\"), assignment_linter() ) expect_lint(\"blah=1\", list(message = \"assignment\", line_number = 1, column_number = 5, type = \"style\"), assignment_linter() ) expect_lint(\"blah=1; blah=2\", list( list(line_number = 1, column_number = 5), list(line_number = 1, column_number = 13), ) assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"other-utilities-for-writing-custom-linters","dir":"Articles","previous_headings":"","what":"Other utilities for writing custom linters","title":"Creating new linters","text":"Besides is_lint_level(), lintr also exports helpers generally useful writing custom linters; used lot internals helpers, ’ve tested demonstrated utility already. get_r_string(): Whenever linter needs examine value character literal (e.g., whether argument value set string), use extract string exactly R see . especially important make logic robust R-4-style raw strings like R\"-(hello)-\", otherwise difficult express, example XPath.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"more-details-about-writing-tests-for-new-lintr-linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"More details about writing tests for new {lintr} linters","title":"Creating new linters","text":"lintr package uses testthat testing. can run currently available tests using devtools::test(). want run tests given file use filter argument devtools::test(). Linter tests put tests/testthat/ folder. test filename linter name prefixed test-, e.g. test-pipe_continuation_linter.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"adding-your-linter-to-the-default_linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Adding your linter to the default_linters","title":"Creating new linters","text":"linter implements part tidyverse style guide can add default_linters. object created file zzz.R (name ensures always run linters defined). Add linter name default_linters list NULL end, add corresponding test case test script ./tests/testthat/default_linter_testcode.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"submit-pull-request","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Submit pull request","title":"Creating new linters","text":"Push changes branch fork lintr repository, submit pull request get linter merged lintr!","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"rstudio","dir":"Articles","previous_headings":"","what":"RStudio","title":"Editor setup","text":"lintr lints automatically displayed RStudio Markers pane (RStudio versions > v0.99.206). RStudio Example order show “Markers” pane RStudio: Menu “Tools” -> “Global Options…”, window title “Options” pop . window: click “Code” left; click “Diagnostics” tab; check “Show diagnostics R”. lint source file test.R type Console lintr::lint(\"test.R\") look result “Markers” pane. package also includes two addins linting current source package. bind addin keyboard shortcut navigate Tools > addins > Browse Addins > Keyboard Shortcuts. ’s recommended use Alt+Shift+L linting current source lint Ctrl+Shift+Alt+L code package. easy remember Alt+Shift+L(int) ;)","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"emacs","dir":"Articles","previous_headings":"","what":"Emacs","title":"Editor setup","text":"lintr built-integration flycheck versions greater 0.23.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation","dir":"Articles","previous_headings":"Emacs","what":"Installation","title":"Editor setup","text":"lintr fully integrated flycheck using ESS. See installation documentation packages information.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration","dir":"Articles","previous_headings":"Emacs","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff. - M-x customize-option -> flycheck-lintr-linters -> linters_with_defaults(line_length_linter(120))","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---syntastic","dir":"Articles","previous_headings":"","what":"Vim - syntastic","title":"Editor setup","text":"lintr can integrated syntastic --fly linting. Vim Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Installation","title":"Editor setup","text":"Put file syntastic/lintr.vim syntastic/syntax_checkers/r. using pathogen directory ~/.vim/bundles/syntastic/syntax_checkers/r. also need add following lines .vimrc.","code":"let g:syntastic_enable_r_lintr_checker = 1 let g:syntastic_r_checkers = ['lintr']"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff.","code":"let g:syntastic_r_lintr_linters = \"linters_with_defaults(line_length_linter(120))\""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---ale","dir":"Articles","previous_headings":"","what":"Vim - ALE","title":"Editor setup","text":"lintr can integrated ALE fly linting.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Installation","title":"Editor setup","text":"lintr integrated ALE requires additional installation.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Configuration","title":"Editor setup","text":"can configure linters used, e.g. using different line length cutoff. can also configure whether lint lint_package used. Set 1 lint_package 0 (default) lint. See :h ale_r_lintr information. Note configuration .lintr files supported. work around can used read contents .lintr file root working directory. allow use configuration .lintr files.","code":"let g:ale_r_lintr_options = \"linters_with_defaults(line_length_linter(120))\" let g:ale_r_lintr_lint_package = 1 if filereadable(\".lintr\") let g:ale_r_lintr_options = join(readfile('.lintr')) endif"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"sublime-text-3","dir":"Articles","previous_headings":"","what":"Sublime Text 3","title":"Editor setup","text":"lintr can integrated Sublime Linter --fly linting. Sublime Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Installation","title":"Editor setup","text":"Simply install sublimeLinter-contrib-lintr using Package Control. information see Sublime Linter Docs","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. disabling assignment linter using different line length cutoff. SublimeLinter User Settings","code":"{ \"linters\": { \"lintr\": { \"linters\": \"linters_with_defaults(assignment_linter = NULL, line_length_linter(120))\" } } }"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"atom","dir":"Articles","previous_headings":"","what":"Atom","title":"Editor setup","text":"lintr can integrated Linter fly linting. Atom Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-4","dir":"Articles","previous_headings":"Atom","what":"Installation","title":"Editor setup","text":"Simply install linter-lintr within Atom command line : information bug reports see Atom linter-lintr.","code":"apm install linter-lintr"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"visual-studio-code","dir":"Articles","previous_headings":"","what":"Visual Studio Code","title":"Editor setup","text":"Visual Studio Code, vscode-R presents lintr diagnostics languageserver. VS Code Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-5","dir":"Articles","previous_headings":"Visual Studio Code","what":"Installation","title":"Editor setup","text":"Installing languageserver package R vscode-R extension VS Code enable lintr VS Code default run following command lines:","code":"Rscript -e 'install.packages(\"languageserver\")' code --install-extension reditorsupport.r"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"running-lintr-on-a-project","dir":"Articles","previous_headings":"","what":"Running lintr on a project","title":"Using lintr","text":"Checking R project lints can done three different functions: Lint single file using lint(): Lint directory using lint_dir(): apply lint() R source files matching pattern argument. default, means .R files well knitr formats (e.g. .Rmd, .Rnw). lint_dir vectorized path, multiple directories can linted time. Lint relevant directories R package using lint_package(): apply lint_dir() subdirectories usually containing R code packages: R containing package implementation. tests containing test code. inst containing sample code vignettes installed along package. vignettes containing package vignettes. data-raw containing code produce data files. information assumed package structure, see R Packages.","code":"lint(filename = \"R/bad.R\") lint_dir(path = \"R\") lint_package(path = \".\")"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"the--lintr-file","dir":"Articles","previous_headings":"Configuring linters","what":"The .lintr file","title":"Using lintr","text":"canonical way configure R projects packages linting create .lintr file project root. file debian control format (?read.dcf), value evaluated R code lintr reading settings. minimal .lintr file can generated running use_lintr() project directory. Lintr supports per-project configuration following fields. linters - see ?linters_with_defaults example specifying non-default linters ?linters_with_tags fine-grained control. exclusions - list filenames exclude linting. can use named item exclude certain lines file. exclude - regex pattern lines exclude linting. Default “# nolint” exclude_start - regex pattern start exclusion range. Default “# nolint start” exclude_end - regex pattern end exclusion range. Default “# nolint end” encoding - encoding used source files. Default inferred .Rproj DESCRIPTION files, fallback UTF-8","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"lintr-file-example","dir":"Articles","previous_headings":"Configuring linters","what":".lintr File Example","title":"Using lintr","text":"example .lintr file uses 120 character line lengths, disables commented_code_linter, excludes couple files.","code":"linters: linters_with_defaults( line_length_linter(120), commented_code_linter = NULL ) exclusions: list( \"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\", \"tests/testthat/exclusions-test\" )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"other-configuration-options","dir":"Articles","previous_headings":"Configuring linters","what":"Other configuration options","title":"Using lintr","text":"generally, lintr searches settings file according following prioritized list. first one found, , used: options(\"lintr.linter_file\") absolute path, file used. default option \".lintr\" value environment variable R_LINTR_LINTER_FILE, set. linter file (, file named like lintr.linter_file) currently-searched directory, .e. directory file passed lint(); linter file .github/linters child directory currently-searched directory. project-local linter file closest parent directory currently-searched directory, starting deepest path, moving upwards one level time. run lint_package(), directory can differ linted file. linter file user’s HOME directory. linter file called config user’s configuration path (given tools::R_user_dir(\"lintr\", = \"config\")). linter file found, default settings take effect (see defaults).","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-options","dir":"Articles","previous_headings":"Configuring linters","what":"Using options()","title":"Using lintr","text":"Values options(), NULL, take precedence linter file (e.g. .lintr). Note key option_name linter file translates R option lintr.option_name. example, options(lintr.exclude = \"# skip lint\") take precedence exclude: # nolint linter file.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-arguments-to-lint","dir":"Articles","previous_headings":"Configuring linters","what":"Using arguments to lint()","title":"Using lintr","text":"settings can also passed arguments linting functions directly. case exclusions, combined globally parsed settings. settings overridden. specified settings changed, remaining settings taken directly defaults, argument parse_settings = FALSE can added function calls. suppress reading .lintr configuration. particularly useful tests exclude example files containing lints package-level .lintr excludes files lints intentional.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"defaults","dir":"Articles","previous_headings":"Configuring linters","what":"Defaults","title":"Using lintr","text":"default settings lintr intended conform tidyverse style guide. However, behavior can customized using different methods. Apart lintr.linter_file, defaults \".lintr\", following settings: Note default encoding setting depends file linted. Encoding found .Rproj file DESCRIPTION file, encoding overrides default UTF-8.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"customizing-active-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Customizing active linters","title":"Using lintr","text":"want customize linters, can use helper function linters_with_defaults(), keep unnamed linters default settings. Disable linter passing NULL. example, set line length limit 120 characters globally disable whitespace_linter(), can put .lintr: default, following linters enabled. applicable, default settings also shown. Another way customize linters specifying tags linters_with_tags(). available tags listed : can select tags interest see linters included: can include tag-based linters configuration file, customize :","code":"linters: linters_with_defaults( line_length_linter = line_length_linter(120L), whitespace_linter = NULL ) lintr::available_tags(packages = \"lintr\") #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"readability\" \"robustness\" #> [13] \"style\" linters <- lintr::linters_with_tags(tags = c(\"package_development\", \"readability\")) names(linters) #> [1] \"backport_linter\" \"boolean_arithmetic_linter\" #> [3] \"brace_linter\" \"commas_linter\" #> [5] \"commented_code_linter\" \"conjunct_test_linter\" #> [7] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [9] \"empty_assignment_linter\" \"expect_comparison_linter\" #> [11] \"expect_identical_linter\" \"expect_length_linter\" #> [13] \"expect_named_linter\" \"expect_not_linter\" #> [15] \"expect_null_linter\" \"expect_s3_class_linter\" #> [17] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [19] \"expect_type_linter\" \"fixed_regex_linter\" #> [21] \"for_loop_index_linter\" \"function_left_parentheses_linter\" #> [23] \"function_return_linter\" \"implicit_assignment_linter\" #> [25] \"indentation_linter\" \"infix_spaces_linter\" #> [27] \"inner_combine_linter\" \"is_numeric_linter\" #> [29] \"lengths_linter\" \"line_length_linter\" #> [31] \"matrix_apply_linter\" \"nested_ifelse_linter\" #> [33] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [35] \"object_usage_linter\" \"outer_negation_linter\" #> [37] \"package_hooks_linter\" \"paren_body_linter\" #> [39] \"pipe_call_linter\" \"pipe_continuation_linter\" #> [41] \"quotes_linter\" \"redundant_equals_linter\" #> [43] \"semicolon_linter\" \"sort_linter\" #> [45] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [47] \"string_boundary_linter\" \"system_file_linter\" #> [49] \"T_and_F_symbol_linter\" \"unnecessary_concatenation_linter\" #> [51] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [53] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [55] \"yoda_test_linter\" linters: linters_with_tags( tags = c(\"package_development\", \"readability\"), yoda_test_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-all-available-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Using all available linters","title":"Using lintr","text":"default lintr configuration includes linters relevant tidyverse style guide, many linters available lintr. can see list available linters using want use available linters, can include .lintr file: want use available linters except , can exclude using NULL:","code":"names(lintr::all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"condition_message_linter\" \"conjunct_test_linter\" #> [13] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [15] \"duplicate_argument_linter\" \"empty_assignment_linter\" #> [17] \"equals_na_linter\" \"expect_comparison_linter\" #> [19] \"expect_identical_linter\" \"expect_length_linter\" #> [21] \"expect_named_linter\" \"expect_not_linter\" #> [23] \"expect_null_linter\" \"expect_s3_class_linter\" #> [25] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [27] \"expect_type_linter\" \"extraction_operator_linter\" #> [29] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [31] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [33] \"function_return_linter\" \"ifelse_censor_linter\" #> [35] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [37] \"indentation_linter\" \"infix_spaces_linter\" #> [39] \"inner_combine_linter\" \"is_numeric_linter\" #> [41] \"lengths_linter\" \"line_length_linter\" #> [43] \"literal_coercion_linter\" \"matrix_apply_linter\" #> [45] \"missing_argument_linter\" \"missing_package_linter\" #> [47] \"namespace_linter\" \"nested_ifelse_linter\" #> [49] \"nonportable_path_linter\" \"numeric_leading_zero_linter\" #> [51] \"object_length_linter\" \"object_name_linter\" #> [53] \"object_usage_linter\" \"outer_negation_linter\" #> [55] \"package_hooks_linter\" \"paren_body_linter\" #> [57] \"paste_linter\" \"pipe_call_linter\" #> [59] \"pipe_continuation_linter\" \"quotes_linter\" #> [61] \"redundant_equals_linter\" \"redundant_ifelse_linter\" #> [63] \"regex_subset_linter\" \"routine_registration_linter\" #> [65] \"semicolon_linter\" \"seq_linter\" #> [67] \"sort_linter\" \"spaces_inside_linter\" #> [69] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [71] \"string_boundary_linter\" \"strings_as_factors_linter\" #> [73] \"system_file_linter\" \"T_and_F_symbol_linter\" #> [75] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [77] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [79] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [81] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [83] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [85] \"unused_import_linter\" \"vector_logic_linter\" #> [87] \"whitespace_linter\" \"yoda_test_linter\" linters: all_linters() linters: all_linters( commented_code_linter = NULL, implicit_integer_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"advanced-programmatic-retrieval-of-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Advanced: programmatic retrieval of linters","title":"Using lintr","text":"use cases, may useful specify linters string instead name, .e. \"assignment_linter\" instead writing assignment_linter(). Beware cases, simple get() enough:","code":"library(lintr) #> #> Attaching package: 'lintr' #> The following object is masked _by_ '.GlobalEnv': #> #> default_settings linter_name <- \"assignment_linter\" withr::with_tempfile(\"tmp\", { writeLines(\"a = 1\", tmp) # linter column is just 'get' print(as.data.frame(lint(tmp, linters = get(linter_name)()))) this_linter <- get(linter_name)() attr(this_linter, \"name\") <- linter_name # linter column is 'assignment_linter' print(as.data.frame(lint(tmp, linters = this_linter))) # more concise alternative: use eval(call(.)) print(as.data.frame(lint(tmp, linters = eval(call(linter_name))))) }) #> filename line_number column_number type #> 1 /tmp/Rtmpb4PWSY/file1e8045288825 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 get #> filename line_number column_number type #> 1 /tmp/Rtmpb4PWSY/file1e8045288825 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter #> filename line_number column_number type #> 1 /tmp/Rtmpb4PWSY/file1e8045288825 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"exclusions","dir":"Articles","previous_headings":"","what":"Exclusions","title":"Using lintr","text":"Sometimes, linters globally disabled. Instead, one might want exclude code linting altogether selectively disable linters part code. Note preferred way excluding lints source code use narrowest possible scope specify exactly linters throw lint marked line. prevents accidental suppression justified lints happen line lint needs suppressed.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-of-code","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines of code","title":"Using lintr","text":"Within source files, special comments can used exclude single lines code linting. lints produced marked line excluded results. default, special comment # nolint: file.R > lint(\"file.R\") file2.R > lint(\"file2.R\") Observe lints suppressed output shown. Sometimes, specific linter needs excluded. case, name linter can appended # nolint comment preceded colon terminated dot.","code":"X = 42L # -------------- this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. X = 42L # nolint ------ this comment overflows the default 80 chars line length."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-only-some-linters","dir":"Articles","previous_headings":"Exclusions","what":"Excluding only some linters","title":"Using lintr","text":"file3.R > lint(\"file3.R\") Observe object_name_linter suppressed. preferable blanket # nolint statements blanket exclusions may accidentally silence linter intentionally suppressed. Multiple linters can specified listing comma separator: file4.R > lint(\"file4.R\") can also specify linter names unique prefix instead full name: file5.R > lint(\"file5.R\")","code":"X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-multiple-lines-of-codes","dir":"Articles","previous_headings":"Exclusions","what":"Excluding multiple lines of codes","title":"Using lintr","text":"linters disabled contiguous block code, exclude_start exclude_end patterns can used. default # nolint start # nolint end respectively. # nolint start accepts syntax # nolint disable specific linters following lines # nolint end encountered. (lints)","code":"# x <- 42L # print(x) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Commented code should be removed. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[commented_code_linter] Commented code should be removed. # nolint start: commented_code_linter. # x <- 42L # print(x) # nolint end"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-via-the-config-file","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines via the config file","title":"Using lintr","text":"Individual lines can also excluded via config file setting key exclusions list elements corresponding different files. exclude lints line 1 file R/bad.R line_length_linter lines 4 6 file, one can set paths interpreted relative location .lintr file.","code":"exclusions: list( \"R/bad.R\" = list( 1, # global exclusions are unnamed line_length_linter = 4:6 ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-files-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding files completely","title":"Using lintr","text":"linter configuration can also used exclude file entirely, linter file entirely. Use sentinel line number Inf mark lines excluded within file. file given character vector, full exclusion implied.","code":"exclusions: list( # excluded from all lints: \"R/excluded1.R\", \"R/excluded2.R\" = Inf, \"R/excluded3.R\" = list(Inf), # excluded from line_length_linter: \"R/no-line-length.R\" = list( line_length_linter = Inf ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-directories-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding directories completely","title":"Using lintr","text":"Entire directories also recognized supplied strings exclusions key. example, exclude renv folder linting R project using renv, set particularly useful projects include external code subdirectories.","code":"exclusions: list( \"renv\" )"},{"path":"https://lintr.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Jim Hester. Author, maintainer. Florent Angly. Author. fangly Russ Hyde. Author. Michael Chirico. Author. Kun Ren. Author. Alexander Rosenstock. Author. AshesITR Indrajeet Patil. Author. @patilindrajeets","code":""},{"path":"https://lintr.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hester J, Angly F, Hyde R, Chirico M, Ren K, Rosenstock , Patil (2023). lintr: 'Linter' R Code. https://github.com/r-lib/lintr, https://lintr.r-lib.org.","code":"@Manual{, title = {lintr: A 'Linter' for R Code}, author = {Jim Hester and Florent Angly and Russ Hyde and Michael Chirico and Kun Ren and Alexander Rosenstock and Indrajeet Patil}, year = {2023}, note = {https://github.com/r-lib/lintr, https://lintr.r-lib.org}, }"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"lintr","dir":"","previous_headings":"","what":"A Linter for R Code","title":"A Linter for R Code","text":"lintr provides static code analysis R. checks adherence given style, identifying syntax errors possible semantic issues, reports can take action. Watch lintr action following animation: lintr complementary {styler} package automatically restyles code, eliminating problems lintr can detect.","code":""},{"path":"https://lintr.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"A Linter for R Code","text":"Install stable version CRAN: development version GitHub:","code":"install.packages(\"lintr\") # install.packages(\"remotes\") remotes::install_github(\"r-lib/lintr\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"A Linter for R Code","text":"can create configuration file run selected linters: see list linters included configuration:","code":"lintr::use_lintr(type = \"tidyverse\") # in a project: lintr::lint_dir() # in a package: lintr::lint_package() # tidyverse (default) names(lintr::linters_with_defaults()) # full names(lintr::all_linters())"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"setting-up-github-actions","dir":"","previous_headings":"Usage","what":"Setting up GitHub Actions","title":"A Linter for R Code","text":"usethis provides helper functions generate lint workflows GitHub Actions: can also run lintr continuous integration within IDE text editor. See vignette(\"continuous-integration\") vignette(\"editors\") details. Without configuration, run default linters. See vignette(\"lintr\") learn modify defaults.","code":"# in a project: usethis::use_github_action(\"lint-project\") # in a package: usethis::use_github_action(\"lint\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"A Linter for R Code","text":"Please note lintr project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter closure — Linter","title":"Create a linter closure — Linter","text":"Create linter closure","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter closure — Linter","text":"","code":"Linter(fun, name = linter_auto_name())"},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter closure — Linter","text":"fun function takes source file returns lint objects. name Default name Linter. Lints produced linter labelled name default.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a linter closure — Linter","text":"function class set 'linter'.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"T and F symbol linter — T_and_F_symbol_linter","title":"T and F symbol linter — T_and_F_symbol_linter","text":"Avoid symbols T F, use TRUE FALSE instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"T_and_F_symbol_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"T and F symbol linter — T_and_F_symbol_linter","text":"best_practices, consistency, default, readability, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"# will produce lints lint( text = \"x <- T; y <- F\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[T_and_F_symbol_linter] Use TRUE instead of the symbol T. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[T_and_F_symbol_linter] Use FALSE instead of the symbol F. lint( text = \"T = 1.2; F = 2.4\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[T_and_F_symbol_linter] Don't use T as a variable name, as it can break code relying on T being TRUE. #> ::warning file=,line=1,col=11::file=,line=1,col=11,[T_and_F_symbol_linter] Don't use F as a variable name, as it can break code relying on F being FALSE. # okay lint( text = \"x <- c(TRUE, FALSE)\", linters = T_and_F_symbol_linter() ) lint( text = \"t = 1.2; f = 2.4\", linters = T_and_F_symbol_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Absolute path linter — absolute_path_linter","title":"Absolute path linter — absolute_path_linter","text":"Check absolute paths used (e.g. \"/var\", \"C:\\System\", \"~/docs\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Absolute path linter — absolute_path_linter","text":"","code":"absolute_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Absolute path linter — absolute_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Absolute path linter — absolute_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Absolute path linter — absolute_path_linter","text":"","code":"# Following examples use raw character constant syntax introduced in R 4.0. # will produce lints lint( text = 'R\"--[/blah/file.txt]--\"', linters = absolute_path_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[absolute_path_linter] Do not use absolute paths. # okay lint( text = 'R\"(./blah)\"', linters = absolute_path_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on all available linters — all_linters","title":"Create a linter configuration based on all available linters — all_linters","text":"Create linter configuration based available linters","code":""},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"all_linters(packages = \"lintr\", ...)"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on all available linters — all_linters","text":"packages character vector packages search linters. ... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"names(all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"condition_message_linter\" \"conjunct_test_linter\" #> [13] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [15] \"duplicate_argument_linter\" \"empty_assignment_linter\" #> [17] \"equals_na_linter\" \"expect_comparison_linter\" #> [19] \"expect_identical_linter\" \"expect_length_linter\" #> [21] \"expect_named_linter\" \"expect_not_linter\" #> [23] \"expect_null_linter\" \"expect_s3_class_linter\" #> [25] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [27] \"expect_type_linter\" \"extraction_operator_linter\" #> [29] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [31] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [33] \"function_return_linter\" \"ifelse_censor_linter\" #> [35] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [37] \"indentation_linter\" \"infix_spaces_linter\" #> [39] \"inner_combine_linter\" \"is_numeric_linter\" #> [41] \"lengths_linter\" \"line_length_linter\" #> [43] \"literal_coercion_linter\" \"matrix_apply_linter\" #> [45] \"missing_argument_linter\" \"missing_package_linter\" #> [47] \"namespace_linter\" \"nested_ifelse_linter\" #> [49] \"nonportable_path_linter\" \"numeric_leading_zero_linter\" #> [51] \"object_length_linter\" \"object_name_linter\" #> [53] \"object_usage_linter\" \"outer_negation_linter\" #> [55] \"package_hooks_linter\" \"paren_body_linter\" #> [57] \"paste_linter\" \"pipe_call_linter\" #> [59] \"pipe_continuation_linter\" \"quotes_linter\" #> [61] \"redundant_equals_linter\" \"redundant_ifelse_linter\" #> [63] \"regex_subset_linter\" \"routine_registration_linter\" #> [65] \"semicolon_linter\" \"seq_linter\" #> [67] \"sort_linter\" \"spaces_inside_linter\" #> [69] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [71] \"string_boundary_linter\" \"strings_as_factors_linter\" #> [73] \"system_file_linter\" \"T_and_F_symbol_linter\" #> [75] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [77] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [79] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [81] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [83] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [85] \"unused_import_linter\" \"vector_logic_linter\" #> [87] \"whitespace_linter\" \"yoda_test_linter\""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"anyDuplicated() exists replacement (duplicated(.)), efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"any_duplicated_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"Also match usage like length(unique(x$col)) == nrow(x), can replaced anyDuplicated(x$col) == 0L.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"# will produce lints lint( text = \"any(duplicated(x), na.rm = TRUE)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). lint( text = \"length(unique(x)) == length(x)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). # okay lint( text = \"anyDuplicated(x)\", linters = any_duplicated_linter() ) lint( text = \"anyDuplicated(x) == 0L\", linters = any_duplicated_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"anyNA() exists replacement (.na(x)) efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"any_is_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"# will produce lints lint( text = \"any(is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). lint( text = \"any(is.na(foo(x)))\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). # okay lint( text = \"anyNA(x)\", linters = any_is_na_linter() ) lint( text = \"anyNA(foo(x))\", linters = any_is_na_linter() ) lint( text = \"any(!is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Assignment linter — assignment_linter","title":"Assignment linter — assignment_linter","text":"Check <- always used assignment.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assignment linter — assignment_linter","text":"","code":"assignment_linter( allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE )"},{"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.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Assignment linter — assignment_linter","text":"configurable, consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Assignment linter — assignment_linter","text":"","code":"# will produce lints lint( text = \"x = mean(x)\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not ->, for assignment. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[assignment_linter] ->> can have hard-to-predict behavior; prefer assigning to a specific environment instead (with assign() or <-). # okay lint( text = \"x <- mean(x)\", linters = assignment_linter() ) code_lines <- \"x <- 1\\ny <<- 2\" writeLines(code_lines) #> x <- 1 #> y <<- 2 lint( text = code_lines, linters = assignment_linter() ) # customizing using arguments code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter(allow_right_assign = TRUE) ) lint( text = \"x <<- 1\", linters = assignment_linter(allow_cascading_assign = FALSE) ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] <<- can have hard-to-predict behavior; prefer assigning to a specific environment instead (with assign() or <-). writeLines(\"foo(bar = \\n 1)\") #> foo(bar = #> 1) lint( text = \"foo(bar = \\n 1)\", linters = assignment_linter(allow_trailing = FALSE) ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[assignment_linter] Assignment = should not be trailing at end of line"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Linter metadata from a package — available_linters","title":"Get Linter metadata from a package — available_linters","text":"available_linters() obtains tagged list Linters available package. available_tags() searches available tags.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Linter metadata from a package — available_linters","text":"","code":"available_linters(packages = \"lintr\", tags = NULL, exclude_tags = \"deprecated\") available_tags(packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Linter metadata from a package — available_linters","text":"packages character vector packages search linters. tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. exclude_tags Tags exclude results. Linters least one matching tag returned. except_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get Linter metadata from a package — available_linters","text":"available_linters returns data frame columns 'linter', 'package' 'tags': linter character column naming function associated linter. package character column containing name package providing linter. tags list column containing tags associated linter. available_tags returns character vector linter tags used packages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"package-authors","dir":"Reference","previous_headings":"","what":"Package Authors","title":"Get Linter metadata from a package — available_linters","text":"implement available_linters() package, include file inst/lintr/linters.csv package. CSV file must contain columns 'linter' 'tags', UTF-8 encoded. Additional columns silently ignored present columns identified name. row describes linter function name (e.g. \"assignment_linter\") column 'linter'. space-separated tags associated linter (e.g. \"style consistency default\") column 'tags'. Tags snake_case. See available_tags(\"lintr\") find tags already used lintr.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get Linter metadata from a package — available_linters","text":"","code":"lintr_linters <- available_linters() # If the package doesn't exist or isn't installed, an empty data frame will be returned available_linters(\"does-not-exist\") #> [1] linter package tags #> <0 rows> (or 0-length row.names) lintr_linters2 <- available_linters(c(\"lintr\", \"does-not-exist\")) identical(lintr_linters, lintr_linters2) #> [1] TRUE available_tags() #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"readability\" \"robustness\" #> [13] \"style\""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Backport linter — backport_linter","title":"Backport linter — backport_linter","text":"Check usage unavailable functions. reliable testing r-devel dependencies.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Backport linter — backport_linter","text":"","code":"backport_linter(r_version = getRversion(), except = character())"},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Backport linter — backport_linter","text":"r_version Minimum R version test compatibility except Character vector functions excluded linting. Use list explicitly defined backports, e.g. imported backports package manually defined package.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Backport linter — backport_linter","text":"configurable, package_development, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Backport linter — backport_linter","text":"","code":"# will produce lints lint( text = \"trimws(x)\", linters = backport_linter(\"3.0.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] trimws (R 3.2.0) is not available for dependency R >= 3.0.0. Use the `except` argument of `backport_linter()` to configure available backports. lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] str2lang (R 3.6.0) is not available for dependency R >= 3.2.0. Use the `except` argument of `backport_linter()` to configure available backports. # okay lint( text = \"trimws(x)\", linters = backport_linter(\"3.6.0\") ) lint( text = \"str2lang(x)\", linters = backport_linter(\"4.0.0\") )"},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Best practices linters — best_practices_linters","title":"Best practices linters — best_practices_linters","text":"Linters checking use coding best practices, explicit typing numeric constants.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Best practices linters — best_practices_linters","text":"following linters tagged 'best_practices': absolute_path_linter any_duplicated_linter any_is_na_linter boolean_arithmetic_linter class_equals_linter commented_code_linter condition_message_linter conjunct_test_linter cyclocomp_linter empty_assignment_linter expect_comparison_linter expect_length_linter expect_named_linter expect_not_linter expect_null_linter expect_s3_class_linter expect_s4_class_linter expect_true_false_linter expect_type_linter extraction_operator_linter fixed_regex_linter for_loop_index_linter function_argument_linter function_return_linter ifelse_censor_linter implicit_assignment_linter implicit_integer_linter is_numeric_linter lengths_linter literal_coercion_linter nonportable_path_linter outer_negation_linter paste_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter seq_linter sort_linter system_file_linter T_and_F_symbol_linter undesirable_function_linter undesirable_operator_linter unnecessary_lambda_linter unnecessary_nested_if_linter unnecessary_placeholder_linter unreachable_code_linter unused_import_linter vector_logic_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"length((x == y)) == 0 !(x == y), latter readable efficient.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"boolean_arithmetic_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"# will produce lints lint( text = \"length(which(x == y)) == 0L\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). lint( text = \"sum(grepl(pattern, x)) == 0\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). # okay lint( text = \"!any(x == y)\", linters = boolean_arithmetic_linter() ) lint( text = \"!any(grepl(pattern, x))\", linters = boolean_arithmetic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Brace linter — brace_linter","title":"Brace linter — brace_linter","text":"Perform various style checks related placement spacing curly braces:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Brace linter — brace_linter","text":"","code":"brace_linter(allow_single_line = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Brace linter — brace_linter","text":"allow_single_line TRUE, allow open closed curly pair line.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Brace linter — brace_linter","text":"Opening curly braces never line always followed newline. Opening curly braces space . Closing curly braces line unless followed else. Closing curly braces conditions line corresponding else. Either neither branch /else use curly braces, .e., either branches use {...} neither . Functions spanning multiple lines use curly braces.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Brace linter — brace_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Brace linter — brace_linter","text":"","code":"# will produce lints lint( text = \"f <- function() { 1 }\", linters = brace_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line. #> ::warning file=,line=1,col=21::file=,line=1,col=21,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. writeLines(\"if (TRUE) {\\n return(1) }\") #> if (TRUE) { #> return(1) } lint( text = \"if (TRUE) {\\n return(1) }\", linters = brace_linter() ) #> ::warning file=,line=2,col=12::file=,line=2,col=12,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. # okay writeLines(\"f <- function() {\\n 1\\n}\") #> f <- function() { #> 1 #> } lint( text = \"f <- function() {\\n 1\\n}\", linters = brace_linter() ) writeLines(\"if (TRUE) { \\n return(1) \\n}\") #> if (TRUE) { #> return(1) #> } lint( text = \"if (TRUE) { \\n return(1) \\n}\", linters = brace_linter() ) # customizing using arguments writeLines(\"if (TRUE) { return(1) }\") #> if (TRUE) { return(1) } lint( text = \"if (TRUE) { return(1) }\", linters = brace_linter(allow_single_line = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Checkstyle Report for lint results — checkstyle_output","title":"Checkstyle Report for lint results — checkstyle_output","text":"Generate report linting results using Checkstyle XML format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Checkstyle Report for lint results — checkstyle_output","text":"","code":"checkstyle_output(lints, filename = \"lintr_results.xml\")"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Checkstyle Report for lint results — checkstyle_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block comparison of class with == — class_equals_linter","title":"Block comparison of class with == — class_equals_linter","text":"Usage like class(x) == \"character\" prone error since class R general vector. correct version S3 classes inherits(): inherits(x, \"character\"). Often, class k . equivalent, example .character() .data.frame().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block comparison of class with == — class_equals_linter","text":"","code":"class_equals_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block comparison of class with == — class_equals_linter","text":"Similar reasoning applies class(x) %% \"character\".","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block comparison of class with == — class_equals_linter","text":"best_practices, consistency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block comparison of class with == — class_equals_linter","text":"","code":"# will produce lints lint( text = 'is_lm <- class(x) == \"lm\"', linters = class_equals_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[class_equals_linter] Instead of comparing class(x) with ==, use inherits(x, 'class-name') or is. or is(x, 'class') lint( text = 'if (\"lm\" %in% class(x)) is_lm <- TRUE', linters = class_equals_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[class_equals_linter] Instead of comparing class(x) with %in%, use inherits(x, 'class-name') or is. or is(x, 'class') # okay lint( text = 'is_lm <- inherits(x, \"lm\")', linters = class_equals_linter() ) lint( text = 'if (inherits(x, \"lm\")) is_lm <- TRUE', linters = class_equals_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":null,"dir":"Reference","previous_headings":"","what":"Clear the lintr cache — clear_cache","title":"Clear the lintr cache — clear_cache","text":"Clear lintr cache","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Clear the lintr cache — clear_cache","text":"","code":"clear_cache(file = NULL, path = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Clear the lintr cache — clear_cache","text":"file filename whose cache clear. pass NULL, delete caches. path directory store caches. Reads option 'lintr.cache_directory' default.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Clear the lintr cache — clear_cache","text":"0 success, 1 failure, invisibly.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commas linter — commas_linter","title":"Commas linter — commas_linter","text":"Check commas followed spaces, spaces .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commas linter — commas_linter","text":"","code":"commas_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commas linter — commas_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commas linter — commas_linter","text":"","code":"# will produce lints lint( text = \"switch(op , x = foo, y = bar)\", linters = commas_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[commas_linter] Commas should never have a space before. lint( text = \"mean(x,trim = 0.2,na.rm = TRUE)\", linters = commas_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[commas_linter] Commas should always have a space after. #> ::warning file=,line=1,col=19::file=,line=1,col=19,[commas_linter] Commas should always have a space after. lint( text = \"x[ ,, drop=TRUE]\", linters = commas_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commas_linter] Commas should never have a space before. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Commas should always have a space after. # okay lint( text = \"switch(op, x = foo, y = bar)\", linters = commas_linter() ) lint( text = \"switch(op, x = , y = bar)\", linters = commas_linter() ) lint( text = \"mean(x, trim = 0.2, na.rm = TRUE)\", linters = commas_linter() ) lint( text = \"a[1, , 2, , 3]\", linters = commas_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commented code linter — commented_code_linter","title":"Commented code linter — commented_code_linter","text":"Check commented code outside roxygen blocks.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commented code linter — commented_code_linter","text":"","code":"commented_code_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commented code linter — commented_code_linter","text":"best_practices, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commented code linter — commented_code_linter","text":"","code":"# will produce lints lint( text = \"# x <- 1\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Commented code should be removed. lint( text = \"x <- f() # g()\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[commented_code_linter] Commented code should be removed. lint( text = \"x + y # + z[1, 2]\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[commented_code_linter] Commented code should be removed. # okay lint( text = \"x <- 1; x <- f(); x + y\", linters = commented_code_linter() ) lint( text = \"#' x <- 1\", linters = commented_code_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Common mistake linters — common_mistakes_linters","title":"Common mistake linters — common_mistakes_linters","text":"Linters highlighting common mistakes, duplicate arguments.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Common mistake linters — common_mistakes_linters","text":"following linters tagged 'common_mistakes': duplicate_argument_linter equals_na_linter missing_argument_linter missing_package_linter redundant_equals_linter sprintf_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"linter discourages combining condition functions like stop() string concatenation functions paste() paste0(). ","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"condition_message_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"stop(paste0(...)) redundant exactly equivalent stop(...) stop(paste(...)) similarly equivalent stop(...) separators (see examples) applies default condition functions well, .e., warning(), message(), packageStartupMessage().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"best_practices, consistency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"# will produce lints lint( text = 'stop(paste(\"a string\", \"another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste to build stop strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). lint( text = 'warning(paste0(\"a string\", \" another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste0 to build warning strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). # okay lint( text = 'stop(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(paste(\"a string\", \"another\", sep = \"-\"))', linters = condition_message_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Configurable linters — configurable_linters","title":"Configurable linters — configurable_linters","text":"Generic linters support custom configuration needs.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Configurable linters — configurable_linters","text":"following linters tagged 'configurable': absolute_path_linter assignment_linter backport_linter brace_linter conjunct_test_linter cyclocomp_linter duplicate_argument_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter line_length_linter missing_argument_linter namespace_linter nonportable_path_linter object_length_linter object_name_linter object_usage_linter paste_linter quotes_linter redundant_ifelse_linter semicolon_linter string_boundary_linter todo_comment_linter trailing_whitespace_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"readability test outputs, testing one thing per call testthat::expect_true() preferable, .e., expect_true(); expect_true(B) better expect_true(&& B), expect_false(); expect_false(B) better expect_false(|| B).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"","code":"conjunct_test_linter(allow_named_stopifnot = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"allow_named_stopifnot Logical, TRUE default. FALSE, \"named\" calls stopifnot(), available since R 4.0.0 provide helpful messages test failures, also linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"Similar reasoning applies && usage inside stopifnot() assertthat::assert_that() calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"best_practices, configurable, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x && y)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of expect_true(A && B), write multiple expectations like expect_true(A) and expect_true(B) The latter will produce better error messages in the case of failure. lint( text = \"expect_false(x || (y && z))\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of expect_false(A || B), write multiple expectations like expect_false(A) and expect_false(B) The latter will produce better error messages in the case of failure. lint( text = \"stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))\", linters = conjunct_test_linter(allow_named_stopifnot = FALSE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of stopifnot(A && B), write multiple conditions like stopifnot(A, B). The latter will produce better error messages in the case of failure. # okay lint( text = \"expect_true(x || (y && z))\", linters = conjunct_test_linter() ) lint( text = 'stopifnot(\"x must be a logical scalar\" = length(x) == 1 && is.logical(x) && !is.na(x))', linters = conjunct_test_linter(allow_named_stopifnot = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"stopifnot() accepts number tests, sequences like stopifnot(x); stopifnot(y) redundant. Ditto tests using assertthat::assert_that() without specifying msg=.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"consecutive_assertion_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"# will produce lints lint( text = \"stopifnot(x); stopifnot(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to stopifnot(). lint( text = \"assert_that(x); assert_that(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to assert_that(). # okay lint( text = \"stopifnot(x, y)\", linters = consecutive_assertion_linter() ) lint( text = 'assert_that(x, msg = \"Bad x!\"); assert_that(y)', linters = consecutive_assertion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Consistency linters — consistency_linters","title":"Consistency linters — consistency_linters","text":"Linters checking enforcing consistent alternative multiple syntactically valid ways write something.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Consistency linters — consistency_linters","text":"following linters tagged 'consistency': assignment_linter class_equals_linter condition_message_linter consecutive_assertion_linter function_argument_linter implicit_integer_linter inner_combine_linter is_numeric_linter literal_coercion_linter numeric_leading_zero_linter object_name_linter paste_linter quotes_linter redundant_ifelse_linter seq_linter system_file_linter T_and_F_symbol_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Correctness linters — correctness_linters","title":"Correctness linters — correctness_linters","text":"Linters highlighting possible programming mistakes, unused variables.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Correctness linters — correctness_linters","text":"following linters tagged 'correctness': duplicate_argument_linter equals_na_linter missing_argument_linter namespace_linter object_usage_linter package_hooks_linter sprintf_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Cyclomatic complexity linter — cyclocomp_linter","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"Check overly complicated expressions. See cyclocomp::cyclocomp().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"cyclocomp_linter(complexity_limit = 15L)"},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"complexity_limit Maximum cyclomatic complexity, default 15. Expressions complex linted. See cyclocomp::cyclocomp().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"best_practices, configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"# will produce lints lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 1L) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[cyclocomp_linter] Functions should have cyclomatic complexity of less than 1, this has 2. # okay lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 2L) )"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Default linters — default_linters","title":"Default linters — default_linters","text":"List default linters lint(). Use linters_with_defaults() customize . default linters based tidyverse style guide. set default linters follows (parameterized linters, e.g., line_length_linter use default argument(s), see ? details):","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default linters — default_linters","text":"","code":"default_linters"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default linters — default_linters","text":"object class list length 25.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Default linters — default_linters","text":"following linters tagged 'default': assignment_linter brace_linter commas_linter commented_code_linter cyclocomp_linter equals_na_linter function_left_parentheses_linter indentation_linter infix_spaces_linter line_length_linter object_length_linter object_name_linter object_usage_linter paren_body_linter pipe_continuation_linter quotes_linter semicolon_linter seq_linter spaces_inside_linter spaces_left_parentheses_linter T_and_F_symbol_linter trailing_blank_lines_linter trailing_whitespace_linter vector_logic_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":null,"dir":"Reference","previous_headings":"","what":"Default lintr settings — default_settings","title":"Default lintr settings — default_settings","text":"default settings consist linters: list default linters (see default_linters()) encoding: character encoding assumed file exclude: pattern used exclude line code exclude_start, exclude_end: patterns used mark start end code block exclude exclude_linter, exclude_linter_sep: patterns used exclude linters exclusions:list files exclude cache_directory: location cache directory comment_token: GitHub token character comment_bot: decides lintr comment bot GitHub can comment commits error_on_lint: decides error produced lints found","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default lintr settings — default_settings","text":"","code":"default_settings"},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default lintr settings — default_settings","text":"object class list length 12.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Default lintr settings — default_settings","text":"","code":"# available settings names(default_settings) #> [1] \"linters\" \"encoding\" \"exclude\" #> [4] \"exclude_start\" \"exclude_end\" \"exclude_linter\" #> [7] \"exclude_linter_sep\" \"exclusions\" \"cache_directory\" #> [10] \"comment_token\" \"comment_bot\" \"error_on_lint\" # linters included by default names(default_settings$linters) #> [1] \"assignment_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"cyclocomp_linter\" \"equals_na_linter\" #> [7] \"function_left_parentheses_linter\" \"indentation_linter\" #> [9] \"infix_spaces_linter\" \"line_length_linter\" #> [11] \"object_length_linter\" \"object_name_linter\" #> [13] \"object_usage_linter\" \"paren_body_linter\" #> [15] \"pipe_continuation_linter\" \"quotes_linter\" #> [17] \"semicolon_linter\" \"seq_linter\" #> [19] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [21] \"T_and_F_symbol_linter\" \"trailing_blank_lines_linter\" #> [23] \"trailing_whitespace_linter\" \"vector_logic_linter\" #> [25] \"whitespace_linter\" # default values for a few of the other settings default_settings[c( \"encoding\", \"exclude\", \"exclude_start\", \"exclude_end\", \"exclude_linter\", \"exclude_linter_sep\", \"exclusions\", \"error_on_lint\" )] #> $encoding #> [1] \"UTF-8\" #> #> $exclude #> #[[:space:]]*nolint #> #> $exclude_start #> #[[:space:]]*nolint start #> #> $exclude_end #> #[[:space:]]*nolint end #> #> $exclude_linter #> ^[[:space:]]*:[[:space:]]*(?(?:(?:[^,.])+[[:space:]]*,[[:space:]]*)*(?:[^,.])+)\\. #> #> $exclude_linter_sep #> [[:space:]]*,[[:space:]]* #> #> $exclusions #> list() #> #> $error_on_lint #> [1] FALSE #>"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":null,"dir":"Reference","previous_headings":"","what":"Default undesirable functions and operators — all_undesirable_functions","title":"Default undesirable functions and operators — all_undesirable_functions","text":"Lists function names operators undesirable_function_linter() undesirable_operator_linter(). list default elements another contains available elements. Use modify_defaults() produce custom list.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default undesirable functions and operators — all_undesirable_functions","text":"","code":"all_undesirable_functions default_undesirable_functions all_undesirable_operators default_undesirable_operators"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default undesirable functions and operators — all_undesirable_functions","text":"named list character strings.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Default undesirable functions and operators — all_undesirable_functions","text":"following functions sometimes regarded undesirable: attach() modifies global search path. Use roxygen2's @importFrom statement packages, :: scripts. browser() pauses execution run likely leftover debugging. removed. debug() traps function causes execution pause function run. removed. debugcall() works similarly debug(), causing execution pause. removed. debugonce() useful interactive debugging. removed. detach() modifies global search path. Detaching environments search path rarely necessary production code. ifelse() type stable. Use /else block scalar logic, use dplyr::if_else()/data.table::fifelse() type stable vectorized logic. .libPaths() permanently modifies library location. Use withr::with_libpaths() temporary change instead. library() modifies global search path. Use roxygen2's @importFrom statement packages, :: scripts. loadNamespace() provide easy way signal failures. Use return value requireNamespace() instead. mapply() type stable. Use Map() guarantee list returned simplify accordingly. options() permanently modifies session options. Use withr::with_options() temporary change instead. par() permanently modifies graphics device parameters. Use withr::with_par() temporary change instead. require() modifies global search path. Use roxygen2's @importFrom statement packages, library() :: scripts. sapply() type stable. Use vapply() appropriate FUN.VALUE= argument obtain type stable simplification. setwd() modifies global working directory. Use withr::with_dir() temporary change instead. sink() permanently redirects output. Use withr::with_sink() temporary redirection instead. source() loads code global environment unless local = TRUE used, can cause unexpected behavior. substring() replaced substr() appropriate stop= value. Sys.setenv() permanently modifies global environment variables. Use withr::with_envvar() temporary change instead. Sys.setlocale() permanently modifies session locale. Use withr::with_locale() temporary change instead. trace() traps function causes execution arbitrary code function run. removed. undebug() useful interactive debugging debug(). removed. untrace() useful interactive debugging trace(). removed. following operators sometimes regarded undesirable: ::: accesses non-exported functions inside packages. Code relying likely break future versions package functions part public interface may changed removed maintainers without notice. Use public functions via :: instead. <<- ->> assign outside current environment way can hard reason . Prefer fully-encapsulated functions wherever possible, , necessary, assign specific environment assign(). Recall can create environment desired scope new.env().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated linters — deprecated_linters","title":"Deprecated linters — deprecated_linters","text":"Linters deprecated provided backwards compatibility . linters excluded linters_with_tags() default.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Deprecated linters — deprecated_linters","text":"following linters tagged 'deprecated': closed_curly_linter consecutive_stopifnot_linter no_tab_linter open_curly_linter paren_brace_linter semicolon_terminator_linter single_quotes_linter unneeded_concatenation_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Duplicate argument linter — duplicate_argument_linter","title":"Duplicate argument linter — duplicate_argument_linter","text":"Check duplicate arguments function calls. cases run-time errors (e.g. mean(x = 1:5, x = 2:3)), otherwise linter used discourage explicitly providing duplicate names objects (e.g. c(= 1, = 2)). Duplicate-named objects hard work programmatically typically avoided.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"duplicate_argument_linter(except = c(\"mutate\", \"transmute\"))"},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Duplicate argument linter — duplicate_argument_linter","text":"except character vector function names exceptions. Defaults functions allow sequential updates variables, currently dplyr::mutate() dplyr::transmute().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Duplicate argument linter — duplicate_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"# will produce lints lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[duplicate_argument_linter] Duplicate arguments in function call. lint( text = \"fun(arg = 1, arg = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[duplicate_argument_linter] Duplicate arguments in function call. # okay lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter(except = \"list\") ) lint( text = \"df %>% dplyr::mutate(x = a + b, x = x + d)\", linters = duplicate_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Efficiency linters — efficiency_linters","title":"Efficiency linters — efficiency_linters","text":"Linters highlighting code efficiency problems, unnecessary function calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Efficiency linters — efficiency_linters","text":"following linters tagged 'efficiency': any_duplicated_linter any_is_na_linter boolean_arithmetic_linter fixed_regex_linter ifelse_censor_linter inner_combine_linter lengths_linter literal_coercion_linter matrix_apply_linter nested_ifelse_linter outer_negation_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter seq_linter sort_linter string_boundary_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unnecessary_lambda_linter vector_logic_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block assignment of {} — empty_assignment_linter","title":"Block assignment of {} — empty_assignment_linter","text":"Assignment {} assignment NULL; use latter clarity. Closely related: unnecessary_concatenation_linter().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"empty_assignment_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block assignment of {} — empty_assignment_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"# will produce lints lint( text = \"x <- {}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. writeLines(\"x = {\\n}\") #> x = { #> } lint( text = \"x = {\\n}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. # okay lint( text = \"x <- { 3 + 4 }\", linters = empty_assignment_linter() ) lint( text = \"x <- NULL\", linters = empty_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality check with NA linter — equals_na_linter","title":"Equality check with NA linter — equals_na_linter","text":"Check x == NA x != NA. usage almost surely incorrect -- checks missing values done .na().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality check with NA linter — equals_na_linter","text":"","code":"equals_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Equality check with NA linter — equals_na_linter","text":"common_mistakes, correctness, default, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality check with NA linter — equals_na_linter","text":"","code":"# will produce lints lint( text = \"x == NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or !=) lint( text = \"x != NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or !=) # okay lint( text = \"is.na(x)\", linters = equals_na_linter() ) lint( text = \"!is.na(x)\", linters = equals_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":null,"dir":"Reference","previous_headings":"","what":"Exclude lines or files from linting — exclude","title":"Exclude lines or files from linting — exclude","text":"Exclude lines files linting","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Exclude lines or files from linting — exclude","text":"","code":"exclude(lints, exclusions = settings$exclusions, linter_names = NULL, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Exclude lines or files from linting — exclude","text":"lints need filtered. exclusions manually specified exclusions linter_names character vector names active linters, used parsing inline exclusions. ... additional arguments passed parse_exclusions()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Exclude lines or files from linting — exclude","text":"Exclusions can specified three different ways. single line source file. default: # nolint, possibly followed listing linters exclude. listing missing, linters excluded line. default listing format # nolint: linter_name, linter2_name.. may anything colon line exclusion tag listing must terminated full stop (.) linter list respected. line range source file. default: # nolint start, # nolint end. # nolint start accepts linter lists form # nolint. exclusions parameter, named list files named lists linters lines exclude , named list files lines exclude, just filenames want exclude entire file, directory names want exclude files directory.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Code executing linters — executing_linters","title":"Code executing linters — executing_linters","text":"Linters evaluate parts linted code, loading referenced packages. linters used untrusted code, may need dependencies linted package project available order function correctly.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Code executing linters — executing_linters","text":"following linters tagged 'executing': namespace_linter object_length_linter object_name_linter object_usage_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"testthat::expect_gt(), testthat::expect_gte(), testthat::expect_lt(), testthat::expect_lte(), testthat::expect_equal() exist specifically testing comparisons two objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"expect_comparison_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x > y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y). lint( text = \"expect_true(x <= y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y). lint( text = \"expect_true(x == (y == 2))\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y). # okay lint( text = \"expect_gt(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_lte(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_identical(x, y == 2)\", linters = expect_comparison_linter() ) lint( text = \"expect_true(x < y | x > y^2)\", linters = expect_comparison_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter enforces usage testthat::expect_identical() default expectation comparisons testthat suite. expect_true(identical(x, y)) equivalent unadvised method test. , testthat::expect_equal() used expect_identical() inappropriate, .e., x y need numerically equivalent instead fully identical (case, provide tolerance= argument expect_equal() explicitly). also applies inconvenient check full equality (e.g., names can ignored, case ignore_attr = \"names\" supplied expect_equal() (, 2nd edition, check.attributes = FALSE).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"expect_identical_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter allows expect_equal() three circumstances: named argument set (e.g. ignore_attr tolerance) Comparison made explicit decimal, e.g. expect_equal(x, 1.0) (implicitly setting tolerance) ... passed (wrapper functions might set arguments ignore_attr tolerance)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, y)\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. lint( text = \"expect_true(identical(x, y))\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. # okay lint( text = \"expect_identical(x, y)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, check.attributes = FALSE)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, tolerance = 1e-6)\", linters = expect_identical_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"testthat::expect_length() exists specifically testing length() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"expect_length_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(length(x), 2L)\", linters = expect_length_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n) # okay lint( text = \"expect_length(x, 2L)\", linters = expect_length_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint expectation — expect_lint","title":"Lint expectation — expect_lint","text":"expectation function test lints produced lint satisfy number checks.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint expectation — expect_lint","text":"","code":"expect_lint(content, checks, ..., file = NULL, language = \"en\")"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lint expectation — expect_lint","text":"content character vector file content linted, vector element representing line text. checks checks performed: NULL check lints returned. single string regex object check single lint returned matching message. named list check single lint returned fields match. Accepted fields taken Lint(). list named lists multiple lints returned, check matches checks corresponding named list (described point ). Named vectors also accepted instead named lists, compatibility feature recommended new code. ... arguments passed lint(), e.g. linters cache use. file NULL, read content specified file rather content. language temporarily override Rs LANGUAGE envvar, controlling localization base R error messages. makes testing reproducible systems irrespective native R language setting.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lint expectation — expect_lint","text":"NULL, invisibly.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint expectation — expect_lint","text":"","code":"# no expected lint expect_lint(\"a\", NULL, trailing_blank_lines_linter()) # one expected lint expect_lint(\"a\\n\", \"superfluous\", trailing_blank_lines_linter()) expect_lint(\"a\\n\", list(message = \"superfluous\", line_number = 2), trailing_blank_lines_linter()) # several expected lints expect_lint(\"a\\n\\n\", list(\"superfluous\", \"superfluous\"), trailing_blank_lines_linter()) expect_lint( \"a\\n\\n\", list( list(message = \"superfluous\", line_number = 2), list(message = \"superfluous\", line_number = 3) ), trailing_blank_lines_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":null,"dir":"Reference","previous_headings":"","what":"Test that the package is lint free — expect_lint_free","title":"Test that the package is lint free — expect_lint_free","text":"function thin wrapper around lint_package simply tests lints package. can used ensure tests fail package contains lints.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test that the package is lint free — expect_lint_free","text":"","code":"expect_lint_free(...)"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test that the package is lint free — expect_lint_free","text":"... arguments passed lint_package()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"testthat::expect_named() exists specifically testing names() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"expect_named_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(names(x), \"a\")', linters = expect_named_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n) # okay lint( text = 'expect_named(x, \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(colnames(x), \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(dimnames(x), \"a\")', linters = expect_named_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"testthat::expect_false() exists specifically testing output FALSE. testthat::expect_true() can also used tests negating output, better use tailored function instead. reverse also true -- use expect_false() instead expect_true(!).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"expect_not_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"# will produce lints lint( text = \"expect_true(!x)\", linters = expect_not_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa. # okay lint( text = \"expect_false(x)\", linters = expect_not_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_null for checking NULL — expect_null_linter","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"Require usage expect_null(x) expect_equal(x, NULL) similar usages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"expect_null_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"testthat::expect_null() exists specifically testing NULL objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_equal(x, NULL) lint( text = \"expect_identical(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_identical(x, NULL) lint( text = \"expect_true(is.null(x))\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_true(is.null(x)) # okay lint( text = \"expect_null(x)\", linters = expect_null_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s3_class() — expect_s3_class_linter","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"testthat::expect_s3_class() exists specifically testing class S3 objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"expect_s3_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(class(x), \"data.frame\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. lint( text = 'expect_equal(class(x), \"numeric\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. # okay lint( text = 'expect_s3_class(x, \"data.frame\")', linters = expect_s3_class_linter() ) lint( text = 'expect_type(x, \"double\")', linters = expect_s3_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"testthat::expect_s4_class() exists specifically testing class S4 objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"expect_s4_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"# will produce lints lint( text = 'expect_true(is(x, \"Matrix\"))', linters = expect_s4_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s4_class_linter] expect_s4_class(x, k) is better than expect_true(is(x, k)). Note also expect_s3_class() available for testing S3 objects. # okay lint( text = 'expect_s4_class(x, \"Matrix\")', linters = expect_s4_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"testthat::expect_true() testthat::expect_false() exist specifically testing TRUE/FALSE value object. testthat::expect_equal() testthat::expect_identical() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"expect_true_false_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, TRUE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE) lint( text = \"expect_equal(x, FALSE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE) # okay lint( text = \"expect_true(x)\", linters = expect_true_false_linter() ) lint( text = \"expect_false(x)\", linters = expect_true_false_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"testthat::expect_type() exists specifically testing storage type objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"expect_type_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t) lint( text = 'expect_identical(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t) # okay lint( text = 'expect_type(x, \"double\")', linters = expect_type_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Extraction operator linter — extraction_operator_linter","title":"Extraction operator linter — extraction_operator_linter","text":"Check [[ operator used extracting single element object, [ (subsetting) $ (interactive use).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extraction operator linter — extraction_operator_linter","text":"","code":"extraction_operator_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extraction operator linter — extraction_operator_linter","text":"three subsetting operators R ([[, [, $) interact differently different data structures (atomic vector, list, data frame, etc.). reasons prefer [[ operator [ $ want extract element data frame list: Subsetting list [ always returns smaller list, [[ returns list element. Subsetting named atomic vector [ returns named vector, [[ returns vector element. Subsetting data frame (tibble) [ type unstable; can return vector data frame. [[, hand, always returns vector. data frame (tibble), $ partial matching (e.g. df$subset df$abc), can source bugs. [[ partial matching. data frames (tibbles), irrespective size, [[ operator slower $. lists, however, reverse true.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Extraction operator linter — extraction_operator_linter","text":"Subsetting chapter Advanced R (Wickham, 2019).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Extraction operator linter — extraction_operator_linter","text":"best_practices, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extraction operator linter — extraction_operator_linter","text":"","code":"# will produce lints lint( text = 'iris[\"Species\"]', linters = extraction_operator_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[extraction_operator_linter] Use `[[` instead of `[` to extract an element. lint( text = \"iris$Species\", linters = extraction_operator_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[extraction_operator_linter] Use `[[` instead of `$` to extract an element. # okay lint( text = 'iris[[\"Species\"]]', linters = extraction_operator_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"Invoking regular expression engine overkill cases search pattern involves static patterns.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"fixed_regex_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"NB: stringr functions, means wrapping pattern stringr::fixed(). NB: linter likely able distinguish every possible case fixed regular expression preferable, rather seeks identify likely cases. never report false positives, however; please report false positives error.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"# will produce lints code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x) lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \".\" with fixed = TRUE. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \"a*b\" with fixed = TRUE. code_lines <- 'stringr::str_subset(x, \"\\\\\\\\$\")' writeLines(code_lines) #> stringr::str_subset(x, \"\\\\$\") lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use stringr::fixed(\"$\") as the pattern. lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \"Munich\" with fixed = TRUE. # okay code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x, fixed = TRUE)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x, fixed = TRUE) lint( text = code_lines, linters = fixed_regex_linter() ) lint( text = 'grepl(\"a*b\", x, fixed = TRUE)', linters = fixed_regex_linter() ) lint( text = 'stringr::str_subset(x, stringr::fixed(\"$\"))', linters = fixed_regex_linter() ) lint( text = 'grepl(\"Munich\", address, fixed = TRUE)', linters = fixed_regex_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"(x x) poor choice indexing variable. overwrites x calling scope confusing read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"for_loop_index_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"best_practices, readability, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"# will produce lints lint( text = \"for (x in x) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. lint( text = \"for (x in foo(x, y)) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. # okay lint( text = \"for (xi in x) { TRUE }\", linters = for_loop_index_linter() ) lint( text = \"for (col in DF$col) { TRUE }\", linters = for_loop_index_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function argument linter — function_argument_linter","title":"Function argument linter — function_argument_linter","text":"Check arguments defaults come last function declarations, per tidyverse design guide. Changing argument order can breaking change. alternative changing argument order instead set default arguments NULL.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function argument linter — function_argument_linter","text":"","code":"function_argument_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function argument linter — function_argument_linter","text":"best_practices, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function argument linter — function_argument_linter","text":"","code":"# will produce lints lint( text = \"function(y = 1, z = 2, x) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[function_argument_linter] Arguments without defaults should come before arguments with defaults. lint( text = \"function(x, y, z = 1, ..., w) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=28::file=,line=1,col=28,[function_argument_linter] Arguments without defaults should come before arguments with defaults. # okay lint( text = \"function(x, y = 1, z = 2) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, w, z = 1, ...) {}\", linters = function_argument_linter() ) lint( text = \"function(y = 1, z = 2, x = NULL) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, z = 1, ..., w = NULL) {}\", linters = function_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function left parentheses linter — function_left_parentheses_linter","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Check left parentheses function call spaces (e.g. mean (1:3)). Although syntactically valid, makes code difficult read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"function_left_parentheses_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Exceptions made control flow functions (, , etc.).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function left parentheses linter — function_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"mean (x)\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. lint( text = \"stats::sd(c (x, y, z))\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. # okay lint( text = \"mean(x)\", linters = function_left_parentheses_linter() ) lint( text = \"stats::sd(c(x, y, z))\", linters = function_left_parentheses_linter() ) lint( text = \"foo <- function(x) (x + 1)\", linters = function_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"return(x <- ...) either distracting (x ignored), confusing (assigning x side effect muddled dual-purpose expression).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"function_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"# will produce lints lint( text = \"foo <- function(x) return(y <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. lint( text = \"foo <- function(x) return(x <<- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. writeLines(\"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\") #> e <- new.env() #> foo <- function(x) return(e$val <- x + 1) lint( text = \"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=2,col=27::file=,line=2,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. # okay lint( text = \"foo <- function(x) return(x + 1)\", linters = function_return_linter() ) code_lines <- \" foo <- function(x) { x <<- x + 1 return(x) } \" lint( text = code_lines, linters = function_return_linter() ) code_lines <- \" e <- new.env() foo <- function(x) { e$val <- x + 1 return(e$val) } \" writeLines(code_lines) #> #> e <- new.env() #> foo <- function(x) { #> e$val <- x + 1 #> return(e$val) #> } #> lint( text = code_lines, linters = function_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract text from STR_CONST nodes — get_r_string","title":"Extract text from STR_CONST nodes — get_r_string","text":"Convert STR_CONST text() values R strings. useful account arbitrary character literals valid since R 4.0, e.g. R\"------[hello]------\", parsed R \"hello\". quite cumbersome write XPaths allowing strings like , whenever linter logic requires testing STR_CONST node's value, use function. NB: also properly vectorized s, accepts variety inputs. Empty inputs become NA outputs, helps ensure length(get_r_string(s)) == length(s).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract text from STR_CONST nodes — get_r_string","text":"","code":"get_r_string(s, xpath = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract text from STR_CONST nodes — get_r_string","text":"s input string strings. s xml_node xml_nodeset xpath NULL, extract string value xml2::xml_text(). s xml_node xml_nodeset xpath specified, extracted xml2::xml_find_chr(). xpath XPath, passed xml2::xml_find_chr() wrapping string().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract text from STR_CONST nodes — get_r_string","text":"","code":"tmp <- withr::local_tempfile(lines = \"c('a', 'b')\") expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f764203756': No such file or directory #> Error in file(con, \"r\"): cannot open the connection writeLines(as.character(expr_as_xml)) #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found get_r_string(expr_as_xml, \"expr[2]\") # \"a\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found get_r_string(expr_as_xml, \"expr[3]\") # \"b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found # more importantly, extract strings under R>=4 raw strings tmp4.0 <- withr::local_tempfile(lines = \"c(R'(a\\\\b)', R'--[a\\\\\\\"\\'\\\"\\\\b]--')\") expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f713afd569': No such file or directory #> Error in file(con, \"r\"): cannot open the connection writeLines(as.character(expr_as_xml4.0)) #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found get_r_string(expr_as_xml4.0, \"expr[2]\") # \"a\\b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found get_r_string(expr_as_xml4.0, \"expr[3]\") # \"a\\\\\"'\\\"\\b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":null,"dir":"Reference","previous_headings":"","what":"Parsed sourced file from a filename — get_source_expressions","title":"Parsed sourced file from a filename — get_source_expressions","text":"object given input linter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"get_source_expressions(filename, lines = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Parsed sourced file from a filename — get_source_expressions","text":"filename file parsed. lines character vector lines. NULL, filename read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Parsed sourced file from a filename — get_source_expressions","text":"list three components: expressions list n+1 objects. first n elements correspond expression filename, consist list 9 elements: filename (character) line (integer) line filename expression begins column (integer) column filename expression begins lines (named character) vector lines spanned expression, named line number corresponding filename parsed_content (data.frame) given utils::getParseData() expression xml_parsed_content (xml_document) XML parse tree expression given xmlparsedata::xml_parse_data() content (character) lines single string (split across lines) (Deprecated) find_line (function) function returning lines expression (Deprecated) find_column (function) similar function columns final element expressions list corresponding full file consisting 6 elements: filename (character) file_lines (character) readLines() output file content (character) .R files, file_lines; .Rmd .qmd scripts, extracted R source code (text) full_parsed_content (data.frame) given utils::getParseData() full content full_xml_parsed_content (xml_document) XML parse tree expressions given xmlparsedata::xml_parse_data() terminal_newline (logical) records whether filename terminal newline (determined readLines() producing corresponding warning) error Lint object describing parsing error. lines readLines() output file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Parsed sourced file from a filename — get_source_expressions","text":"file read using encoding setting. setting found taking first valid result following locations encoding key usual lintr configuration settings. Encoding field Package DESCRIPTION file parent directory. Encoding field R Project .Rproj file parent directory. \"UTF-8\" fallback.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) get_source_expressions(tmp) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f776b32b96': No such file or directory #> Error in file(con, \"r\"): cannot open the connection"},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":null,"dir":"Reference","previous_headings":"","what":"Get parsed IDs by token — ids_with_token","title":"Get parsed IDs by token — ids_with_token","text":"Gets source IDs (row indices) corresponding given token.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get parsed IDs by token — ids_with_token","text":"","code":"ids_with_token(source_expression, value, fun = `==`, source_file = NULL) with_id(source_expression, id, source_file)"},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get parsed IDs by token — ids_with_token","text":"source_expression list source expressions, result call get_source_expressions(), desired filename. value Character. String corresponding token search . example: \"SYMBOL\" \"FUNCTION\" \"EQ_FORMALS\" \"$\" \"(\" fun additional flexibility, function search token column parsed_content. Typically == %%. source_file (DEPRECATED) source_expression. removed. id Integer. index corresponding desired row parsed_content.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get parsed IDs by token — ids_with_token","text":"ids_with_token: indices parsed_content data frame entry list source expressions. Indices correspond rows fun evaluates TRUE value token column. with_id: data frame corresponding row(s) specified id.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Get parsed IDs by token — ids_with_token","text":"with_id(): Return row parsed_content entry [get_source_expressions]() object. Typically used conjunction ids_with_token iterate rows containing desired tokens.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get parsed IDs by token — ids_with_token","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) source_exprs <- get_source_expressions(tmp) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f76e4dd239': No such file or directory #> Error in file(con, \"r\"): cannot open the connection ids_with_token(source_exprs$expressions[[1L]], value = \"SYMBOL\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found with_id(source_exprs$expressions[[1L]], 2L) #> Error in eval(expr, envir, enclos): object 'source_exprs' not found"},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"ifelse(x > M, M, x) pmin(x, M), harder read requires several passes vector.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"","code":"ifelse_censor_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"goes similar ways censor vector, e.g. ifelse(x <= M, x, M) pmin(x, M), ifelse(x < m, m, x) pmax(x, m), ifelse(x >= m, x, m) pmax(x, m).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"","code":"# will produce lints lint( text = \"ifelse(5:1 < pi, 5:1, pi)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmin(x, y) is preferable to ifelse(x < y, x, y). lint( text = \"ifelse(x > 0, x, 0)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmax(x, y) is preferable to ifelse(x > y, x, y). # okay lint( text = \"pmin(5:1, pi)\", linters = ifelse_censor_linter() ) lint( text = \"pmax(x, 0)\", linters = ifelse_censor_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Avoid implicit assignment in function calls — implicit_assignment_linter","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"Assigning inside function calls makes code difficult read, avoided, except functions capture side-effects (e.g. capture.output()).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"implicit_assignment_linter( except = c(\"bquote\", \"expression\", \"expr\", \"quo\", \"quos\", \"quote\") )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"except character vector functions excluded linting.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"best_practices, configurable, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"# will produce lints lint( text = \"if (x <- 1L) TRUE\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. lint( text = \"mean(x <- 1:4)\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. # okay writeLines(\"x <- 1L\\nif (x) TRUE\") #> x <- 1L #> if (x) TRUE lint( text = \"x <- 1L\\nif (x) TRUE\", linters = implicit_assignment_linter() ) writeLines(\"x <- 1:4\\nmean(x)\") #> x <- 1:4 #> mean(x) lint( text = \"x <- 1:4\\nmean(x)\", linters = implicit_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Implicit integer linter — implicit_integer_linter","title":"Implicit integer linter — implicit_integer_linter","text":"Check integers explicitly typed using form 1L instead 1.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Implicit integer linter — implicit_integer_linter","text":"","code":"implicit_integer_linter(allow_colon = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Implicit integer linter — implicit_integer_linter","text":"allow_colon Logical, default FALSE. TRUE, expressions involving : throw lint regardless whether inputs implicitly integers.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Implicit integer linter — implicit_integer_linter","text":"best_practices, configurable, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Implicit integer linter — implicit_integer_linter","text":"","code":"# will produce lints lint( text = \"x <- 1\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. lint( text = \"x[2]\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=4::file=,line=1,col=4,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. lint( text = \"1:10\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. # okay lint( text = \"x <- 1.0\", linters = implicit_integer_linter() ) lint( text = \"x <- 1L\", linters = implicit_integer_linter() ) lint( text = \"x[2L]\", linters = implicit_integer_linter() ) lint( text = \"1:10\", linters = implicit_integer_linter(allow_colon = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that indentation is consistent — indentation_linter","title":"Check that indentation is consistent — indentation_linter","text":"Check indentation consistent","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that indentation is consistent — indentation_linter","text":"","code":"indentation_linter( indent = 2L, hanging_indent_style = c(\"tidy\", \"always\", \"never\"), assignment_as_infix = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that indentation is consistent — indentation_linter","text":"indent Number spaces, code block indented relative parent code block. Used multi-line code blocks ({ ... }), function calls (( ... )) extractions ([ ... ], [[ ... ]]). Defaults 2. hanging_indent_style Indentation style multi-line function calls arguments first line. Defaults tidyverse style, .e. block indent used function call terminates ) separate line hanging indent . Note function multi-line function calls without arguments first line always expected block-indented arguments. hanging_indent_style \"tidy\", multi-line function definitions expected double-indented first line function definition contains arguments closing parenthesis line. assignment_as_infix Treat <- regular (.e. left-associative) infix operator? means, infix operators right hand side assignment trigger second level indentation:","code":"# complies to any style map( x, f, additional_arg = 42 ) # complies to \"tidy\" and \"never\" map(x, f, additional_arg = 42 ) # complies to \"always\" map(x, f, additional_arg = 42 ) # complies to \"tidy\" and \"always\" map(x, f, additional_arg = 42) # complies to \"never\" map(x, f, additional_arg = 42) # complies to \"tidy\" function( a, b) { # body } # complies to any style variable <- a %+% b %+% c # complies to assignment_as_infix = TRUE variable <- a %+% b %+% c # complies to assignment_as_infix = FALSE variable <- a %+% b %+% c"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check that indentation is consistent — indentation_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check that indentation is consistent — indentation_linter","text":"","code":"# will produce lints code_lines <- \"if (TRUE) {\\n1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=0::file=,line=2,col=0,[indentation_linter] Indentation should be 2 spaces but is 0 spaces. code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"always\") ) #> ::warning file=,line=2,col=2::file=,line=2,col=2,[indentation_linter] Hanging indent should be 4 spaces but is 2 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"never\") ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. # okay code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter() ) code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter(indent = 4) )"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Infix spaces linter — infix_spaces_linter","title":"Infix spaces linter — infix_spaces_linter","text":"Check infix operators surrounded spaces. Enforces corresponding Tidyverse style guide rule; see https://style.tidyverse.org/syntax.html#infix-operators.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"infix_spaces_linter(exclude_operators = NULL, allow_multiple_spaces = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Infix spaces linter — infix_spaces_linter","text":"exclude_operators Character vector operators exclude consideration linting. Default include following \"low-precedence\" operators: +, -, ~, >, >=, <, <=, ==, !=, &, &&, |, ||, <-, :=, <<-, ->, ->>, =, /, *, infix operator (exclude infixes passing \"%%\"). Note <-, :=, <<- included/excluded group (indicated passing \"<-\"), -> ->> (viz, \"->\"), = assignment setting arguments calls treated . allow_multiple_spaces Logical, default TRUE. FALSE, usage like x = 2 also linted; excluded default usage can sometimes used better code alignment, allowed style guide.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Infix spaces linter — infix_spaces_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"# will produce lints lint( text = \"x<-1L\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators. lint( text = \"1:4 %>%sum()\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[infix_spaces_linter] Put spaces around all infix operators. # okay lint( text = \"x <- 1L\", linters = infix_spaces_linter() ) lint( text = \"1:4 %>% sum()\", linters = infix_spaces_linter() ) code_lines <- \" ab <- 1L abcdef <- 2L \" writeLines(code_lines) #> #> ab <- 1L #> abcdef <- 2L #> lint( text = code_lines, linters = infix_spaces_linter(allow_multiple_spaces = TRUE) ) lint( text = \"a||b\", linters = infix_spaces_linter(exclude_operators = \"||\") )"},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":".Date(c(, b)) logically equivalent c(.Date(), .Date(b)). equivalence holds several vectorized functions like .POSIXct() math functions like sin(). former preferred expensive part operation (.Date()) applied .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"","code":"inner_combine_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"","code":"# will produce lints lint( text = \"c(log10(x), log10(y), log10(z))\", linters = inner_combine_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[inner_combine_linter] Combine inputs to vectorized functions first to take full advantage of vectorization, e.g., log10(c(x, y)) only runs the more expensive log10() once as compared to c(log10(x), log10(y)). # okay lint( text = \"log10(c(x, y, z))\", linters = inner_combine_linter() ) lint( text = \"c(log(x, base = 10), log10(x, base = 2))\", linters = inner_combine_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":null,"dir":"Reference","previous_headings":"","what":"Is this an expression- or a file-level source object? — is_lint_level","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"Helper determining whether current source_expression contains expressions current file, just single expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"is_lint_level(source_expression, level = c(\"expression\", \"file\"))"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"source_expression parsed expression object, .e., element object returned get_source_expressions(). level level expression tested? \"expression\" means individual expression, \"file\" means expressions current file available.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) source_exprs <- get_source_expressions(tmp) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f7cb70d60': No such file or directory #> Error in file(con, \"r\"): cannot open the connection is_lint_level(source_exprs$expressions[[1L]], level = \"expression\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[1L]], level = \"file\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[3L]], level = \"expression\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[3L]], level = \"file\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found"},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":".numeric() returns TRUE typeof(x) double integer -- testing .numeric(x) || .integer(x) thus redundant.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"","code":"is_numeric_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"NB: linter plays well class_equals_linter(), can help avoid .numeric() equivalents like (class(x) == c(\"numeric\", \"integer\")).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"","code":"# will produce lints lint( text = \"is.numeric(y) || is.integer(y)\", linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as is.numeric(x) || is.integer(x). Use is.double(x) to test for objects stored as 64-bit floating point. lint( text = 'class(z) %in% c(\"numeric\", \"integer\")', linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as class(x) %in% c(\"integer\", \"numeric\"). Use is.double(x) to test for objects stored as 64-bit floating point. # okay lint( text = \"is.numeric(y) || is.factor(y)\", linters = is_numeric_linter() ) lint( text = 'class(z) %in% c(\"numeric\", \"integer\", \"factor\")', linters = is_numeric_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of lengths() where possible — lengths_linter","title":"Require usage of lengths() where possible — lengths_linter","text":"lengths() function added base R version 3.2.0 get length element list. equivalent sapply(x, length), faster readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of lengths() where possible — lengths_linter","text":"","code":"lengths_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of lengths() where possible — lengths_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of lengths() where possible — lengths_linter","text":"","code":"# will produce lints lint( text = \"sapply(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"vapply(x, length, integer(1L))\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"purrr::map_int(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. # okay lint( text = \"lengths(x)\", linters = lengths_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Line length linter — line_length_linter","title":"Line length linter — line_length_linter","text":"Check line length comments code less length.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Line length linter — line_length_linter","text":"","code":"line_length_linter(length = 80L)"},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Line length linter — line_length_linter","text":"length maximum line length allowed. Default 80L (Hollerith limit).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Line length linter — line_length_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Line length linter — line_length_linter","text":"","code":"# will produce lints lint( text = strrep(\"x\", 23L), linters = line_length_linter(length = 20L) ) #> ::warning file=,line=1,col=21::file=,line=1,col=21,[line_length_linter] Lines should not be more than 20 characters. # okay lint( text = strrep(\"x\", 21L), linters = line_length_linter(length = 40L) )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a lint object — lint-s3","title":"Create a lint object — lint-s3","text":"Create lint object","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a lint object — lint-s3","text":"","code":"Lint( filename, line_number = 1L, column_number = 1L, type = c(\"style\", \"warning\", \"error\"), message = \"\", line = \"\", ranges = NULL, linter = \"\" )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a lint object — lint-s3","text":"filename path source file linted. line_number line number lint occurred. column_number column number lint occurred. type type lint. message message used describe lint error line code source lint occurred ranges list ranges line emphasized. linter deprecated. longer used.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a lint object — lint-s3","text":"object class c(\"lint\", \"list\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint a file, directory, or package — lint","title":"Lint a file, directory, or package — lint","text":"lint() lints single file. lint_dir() lints files directory. lint_package() lints likely locations R files package, .e. R/, tests/, inst/, vignettes/, data-raw/, demo/, exec/.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint a file, directory, or package — lint","text":"","code":"lint( filename, linters = NULL, ..., cache = FALSE, parse_settings = TRUE, text = NULL ) lint_dir( path = \".\", ..., relative_path = TRUE, exclusions = list(\"renv\", \"packrat\"), pattern = rex::rex(\".\", one_of(\"Rr\"), or(\"\", \"html\", \"md\", \"nw\", \"rst\", \"tex\", \"txt\"), end), parse_settings = TRUE ) lint_package( path = \".\", ..., relative_path = TRUE, exclusions = list(\"R/RcppExports.R\"), parse_settings = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lint a file, directory, or package — lint","text":"filename either filename file lint, character string inline R code linting. latter (inline data) applies whenever filename newline character (\\n). linters named list linter functions apply. See linters full list default available linters. ... Provide additional arguments passed : exclude() (case lint(); e.g. lints exclusions) lint() (case lint_dir() lint_package(); e.g. linters cache) cache given logical, toggle caching lint results. passed character string, store cache directory. parse_settings whether try parse settings. text Optional argument supplying string lines directly, e.g. file already memory linting done ad hoc. path base directory project (lint_dir()) package (lint_package()). relative_path TRUE, file paths printed using path relative base directory. FALSE, use full absolute path. exclusions exclusions exclude(), relative package path. pattern pattern files, default take files extensions .R, .Rmd, .qmd, .Rnw, .Rhtml, .Rrst, .Rtex, .Rtxt allowing lowercase r (.r, ...).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lint a file, directory, or package — lint","text":"object class c(\"lints\", \"list\"), element \"list\" object.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Lint a file, directory, or package — lint","text":"Read vignette(\"lintr\") learn configure linters run default. Note files contain unparseable encoding problems, encoding problem linted avoid unintelligible error messages linters.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint a file, directory, or package — lint","text":"","code":"f <- withr::local_tempfile(lines = \"a=1\", fileext = \"R\") lint(f) # linting a file #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f743768017R': No such file or directory #> Error in file(con, \"r\"): cannot open the connection lint(\"a = 123\\n\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. lint(text = \"a = 123\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. if (FALSE) { lint_dir() lint_dir( linters = list(semicolon_linter()), exclusions = list( \"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\", \"renv\" ) ) } if (FALSE) { lint_package() lint_package( linters = linters_with_defaults(semicolon_linter = semicolon_linter()), exclusions = list(\"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\") ) }"},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Available linters — linters","title":"Available linters — linters","text":"variety linters available lintr. popular ones readily accessible default_linters(). Within lint() function call, linters use initialized provided arguments fed source file (provided get_source_expressions()). data frame available linters can retrieved using available_linters(). Documentation linters structured tags allow easier discovery; see also available_tags().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Available linters — linters","text":"following tags exist: best_practices (50 linters) common_mistakes (7 linters) configurable (29 linters) consistency (18 linters) correctness (7 linters) default (25 linters) deprecated (8 linters) efficiency (23 linters) executing (5 linters) package_development (14 linters) readability (47 linters) robustness (14 linters) style (34 linters)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Available linters — linters","text":"following linters exist: absolute_path_linter (tags: best_practices, configurable, robustness) any_duplicated_linter (tags: best_practices, efficiency) any_is_na_linter (tags: best_practices, efficiency) assignment_linter (tags: configurable, consistency, default, style) backport_linter (tags: configurable, package_development, robustness) boolean_arithmetic_linter (tags: best_practices, efficiency, readability) brace_linter (tags: configurable, default, readability, style) class_equals_linter (tags: best_practices, consistency, robustness) commas_linter (tags: default, readability, style) commented_code_linter (tags: best_practices, default, readability, style) condition_message_linter (tags: best_practices, consistency) conjunct_test_linter (tags: best_practices, configurable, package_development, readability) consecutive_assertion_linter (tags: consistency, readability, style) cyclocomp_linter (tags: best_practices, configurable, default, readability, style) duplicate_argument_linter (tags: common_mistakes, configurable, correctness) empty_assignment_linter (tags: best_practices, readability) equals_na_linter (tags: common_mistakes, correctness, default, robustness) expect_comparison_linter (tags: best_practices, package_development) expect_identical_linter (tags: package_development) expect_length_linter (tags: best_practices, package_development, readability) expect_named_linter (tags: best_practices, package_development, readability) expect_not_linter (tags: best_practices, package_development, readability) expect_null_linter (tags: best_practices, package_development) expect_s3_class_linter (tags: best_practices, package_development) expect_s4_class_linter (tags: best_practices, package_development) expect_true_false_linter (tags: best_practices, package_development, readability) expect_type_linter (tags: best_practices, package_development) extraction_operator_linter (tags: best_practices, style) fixed_regex_linter (tags: best_practices, efficiency, readability) for_loop_index_linter (tags: best_practices, readability, robustness) function_argument_linter (tags: best_practices, consistency, style) function_left_parentheses_linter (tags: default, readability, style) function_return_linter (tags: best_practices, readability) ifelse_censor_linter (tags: best_practices, efficiency) implicit_assignment_linter (tags: best_practices, configurable, readability, style) implicit_integer_linter (tags: best_practices, configurable, consistency, style) indentation_linter (tags: configurable, default, readability, style) infix_spaces_linter (tags: configurable, default, readability, style) inner_combine_linter (tags: consistency, efficiency, readability) is_numeric_linter (tags: best_practices, consistency, readability) lengths_linter (tags: best_practices, efficiency, readability) line_length_linter (tags: configurable, default, readability, style) literal_coercion_linter (tags: best_practices, consistency, efficiency) matrix_apply_linter (tags: efficiency, readability) missing_argument_linter (tags: common_mistakes, configurable, correctness) missing_package_linter (tags: common_mistakes, robustness) namespace_linter (tags: configurable, correctness, executing, robustness) nested_ifelse_linter (tags: efficiency, readability) nonportable_path_linter (tags: best_practices, configurable, robustness) numeric_leading_zero_linter (tags: consistency, readability, style) object_length_linter (tags: configurable, default, executing, readability, style) object_name_linter (tags: configurable, consistency, default, executing, style) object_usage_linter (tags: configurable, correctness, default, executing, readability, style) outer_negation_linter (tags: best_practices, efficiency, readability) package_hooks_linter (tags: correctness, package_development, style) paren_body_linter (tags: default, readability, style) paste_linter (tags: best_practices, configurable, consistency) pipe_call_linter (tags: readability, style) pipe_continuation_linter (tags: default, readability, style) quotes_linter (tags: configurable, consistency, default, readability, style) redundant_equals_linter (tags: best_practices, common_mistakes, efficiency, readability) redundant_ifelse_linter (tags: best_practices, configurable, consistency, efficiency) regex_subset_linter (tags: best_practices, efficiency) routine_registration_linter (tags: best_practices, efficiency, robustness) semicolon_linter (tags: configurable, default, readability, style) seq_linter (tags: best_practices, consistency, default, efficiency, robustness) sort_linter (tags: best_practices, efficiency, readability) spaces_inside_linter (tags: default, readability, style) spaces_left_parentheses_linter (tags: default, readability, style) sprintf_linter (tags: common_mistakes, correctness) string_boundary_linter (tags: configurable, efficiency, readability) strings_as_factors_linter (tags: robustness) system_file_linter (tags: best_practices, consistency, readability) T_and_F_symbol_linter (tags: best_practices, consistency, default, readability, robustness, style) todo_comment_linter (tags: configurable, style) trailing_blank_lines_linter (tags: default, style) trailing_whitespace_linter (tags: configurable, default, style) undesirable_function_linter (tags: best_practices, configurable, efficiency, robustness, style) undesirable_operator_linter (tags: best_practices, configurable, efficiency, robustness, style) unnecessary_concatenation_linter (tags: configurable, efficiency, readability, style) unnecessary_lambda_linter (tags: best_practices, efficiency, readability) unnecessary_nested_if_linter (tags: best_practices, readability) unnecessary_placeholder_linter (tags: best_practices, readability) unreachable_code_linter (tags: best_practices, readability) unused_import_linter (tags: best_practices, common_mistakes, configurable, executing) vector_logic_linter (tags: best_practices, default, efficiency) whitespace_linter (tags: consistency, default, style) yoda_test_linter (tags: best_practices, package_development, readability)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on defaults — linters_with_defaults","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"Make new list based lintr's default linters. result function meant passed linters argument lint(), put configuration file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"","code":"linters_with_defaults(..., defaults = default_linters) with_defaults(..., default = default_linters)"},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed. defaults, default Default list linters modify. Must named.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"","code":"# When using interactively you will usually pass the result onto `lint` or `lint_package()` f <- withr::local_tempfile(lines = \"my_slightly_long_variable_name <- 2.3\", fileext = \"R\") lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120))) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f736907d5fR': No such file or directory #> Error in file(con, \"r\"): cannot open the connection # the default linter list with a different line length cutoff my_linters <- linters_with_defaults(line_length_linter = line_length_linter(120)) # omit the argument name if you are just using different arguments my_linters <- linters_with_defaults(defaults = my_linters, object_name_linter(\"camelCase\")) # remove assignment checks (with NULL), add absolute path checks my_linters <- linters_with_defaults( defaults = my_linters, assignment_linter = NULL, absolute_path_linter() ) # checking the included linters names(my_linters) #> [1] \"absolute_path_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"cyclocomp_linter\" \"equals_na_linter\" #> [7] \"function_left_parentheses_linter\" \"indentation_linter\" #> [9] \"infix_spaces_linter\" \"line_length_linter\" #> [11] \"object_length_linter\" \"object_name_linter\" #> [13] \"object_usage_linter\" \"paren_body_linter\" #> [15] \"pipe_continuation_linter\" \"quotes_linter\" #> [17] \"semicolon_linter\" \"seq_linter\" #> [19] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [21] \"T_and_F_symbol_linter\" \"trailing_blank_lines_linter\" #> [23] \"trailing_whitespace_linter\" \"vector_logic_linter\" #> [25] \"whitespace_linter\""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a tag-based linter configuration — linters_with_tags","title":"Create a tag-based linter configuration — linters_with_tags","text":"Make new list based linters provided packages tagged tags. result function meant passed linters argument lint(), put configuration file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a tag-based linter configuration — linters_with_tags","text":"","code":"linters_with_tags(tags, ..., packages = \"lintr\", exclude_tags = \"deprecated\")"},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a tag-based linter configuration — linters_with_tags","text":"tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. ... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed. packages character vector packages search linters. exclude_tags Tags exclude results. Linters least one matching tag returned. except_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a tag-based linter configuration — linters_with_tags","text":"modified list linters.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a tag-based linter configuration — linters_with_tags","text":"","code":"# `linters_with_defaults()` and `linters_with_tags(\"default\")` are the same: all.equal(linters_with_defaults(), linters_with_tags(\"default\")) #> [1] TRUE # Get all linters useful for package development linters <- linters_with_tags(tags = c(\"package_development\", \"style\")) names(linters) #> [1] \"assignment_linter\" \"backport_linter\" #> [3] \"brace_linter\" \"commas_linter\" #> [5] \"commented_code_linter\" \"conjunct_test_linter\" #> [7] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [9] \"expect_comparison_linter\" \"expect_identical_linter\" #> [11] \"expect_length_linter\" \"expect_named_linter\" #> [13] \"expect_not_linter\" \"expect_null_linter\" #> [15] \"expect_s3_class_linter\" \"expect_s4_class_linter\" #> [17] \"expect_true_false_linter\" \"expect_type_linter\" #> [19] \"extraction_operator_linter\" \"function_argument_linter\" #> [21] \"function_left_parentheses_linter\" \"implicit_assignment_linter\" #> [23] \"implicit_integer_linter\" \"indentation_linter\" #> [25] \"infix_spaces_linter\" \"line_length_linter\" #> [27] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [29] \"object_name_linter\" \"object_usage_linter\" #> [31] \"package_hooks_linter\" \"paren_body_linter\" #> [33] \"pipe_call_linter\" \"pipe_continuation_linter\" #> [35] \"quotes_linter\" \"semicolon_linter\" #> [37] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [39] \"T_and_F_symbol_linter\" \"todo_comment_linter\" #> [41] \"trailing_blank_lines_linter\" \"trailing_whitespace_linter\" #> [43] \"undesirable_function_linter\" \"undesirable_operator_linter\" #> [45] \"unnecessary_concatenation_linter\" \"whitespace_linter\" #> [47] \"yoda_test_linter\" # Get all linters tagged as \"default\" from lintr and mypkg if (FALSE) { linters_with_tags(\"default\", packages = c(\"lintr\", \"mypkg\")) }"},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated functions in lintr — lintr-deprecated","title":"Deprecated functions in lintr — lintr-deprecated","text":"functions deprecated lintr. open_curly_linter() closed_curly_linter() check open closed curly braces line unless follow else, comma, closing bracket. Deprecated favor brace_linter(). paren_brace_linter() checks space right parentheses opening curly brace. E.g., function(){} space, function() {} . Deprecated favor brace_linter(). semicolon_terminator_linter() checks semicolons terminate expressions. Deprecated favor semicolon_linter().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deprecated functions in lintr — lintr-deprecated","text":"","code":"closed_curly_linter(allow_single_line = FALSE) open_curly_linter(allow_single_line = FALSE) paren_brace_linter() semicolon_terminator_linter(semicolon = c(\"compound\", \"trailing\")) unneeded_concatenation_linter(allow_single_expression = TRUE) single_quotes_linter() consecutive_stopifnot_linter() no_tab_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deprecated functions in lintr — lintr-deprecated","text":"allow_single_line TRUE, allow open closed curly pair line. semicolon character vector defining semicolons report: compound Semicolons separate two statements line. trailing Semicolons following last statement line.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Deprecated functions in lintr — lintr-deprecated","text":"configurable, deprecated, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lintr-package.html","id":null,"dir":"Reference","previous_headings":"","what":"Lintr — lintr-package","title":"Lintr — lintr-package","text":"Checks adherence given style, syntax errors, possible semantic issues. Supports fly checking R code edited Emacs, Vim, Sublime Text.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lintr-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Lintr — lintr-package","text":"Maintainer: Jim Hester james.f.hester@gmail.com Authors: Florent Angly (fangly) Russ Hyde Michael Chirico Kun Ren Alexander Rosenstock (AshesITR) Indrajeet Patil patilindrajeet.science@gmail.com (ORCID) (@patilindrajeets)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":".integer(1) (rlang::int(1)) 1L latter concise gets typed correctly compilation.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"","code":"literal_coercion_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"applies missing sentinels like NA -- typically, necessary specify storage type NA, , prefer using typed version (e.g. NA_real_) instead coercion (like .numeric(NA)).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"best_practices, consistency, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"","code":"# will produce lints lint( text = \"int(1)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use 1L instead of int(1), i.e., use literals directly where possible, instead of coercion. lint( text = \"as.character(NA)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use NA_character_ instead of as.character(NA), i.e., use literals directly where possible, instead of coercion. lint( text = \"rlang::lgl(1L)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use TRUE instead of rlang::lgl(1L), i.e., use literals directly where possible, instead of coercion. # okay lint( text = \"1L\", linters = literal_coercion_linter() ) lint( text = \"NA_character_\", linters = literal_coercion_linter() ) lint( text = \"TRUE\", linters = literal_coercion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"colSums() rowSums() clearer performant alternatives apply(x, 2, sum) apply(x, 1, sum) respectively case 2D arrays, matrices","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"matrix_apply_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"# will produce lints lint( text = \"apply(x, 1, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(x) rather than apply(x, 1, sum) lint( text = \"apply(x, 2, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x)) or colSums(x) if x has 2 dimensions rather than apply(x, 2, sum) lint( text = \"apply(x, 2, sum, na.rm = TRUE)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x, na.rm = TRUE)) or colSums(x, na.rm = TRUE) if x has 2 dimensions rather than apply(x, 2, sum, na.rm = TRUE) lint( text = \"apply(x, 2:4, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x), dims = 3) or colSums(x) if x has 4 dimensions rather than apply(x, 2:4, sum)"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing argument linter — missing_argument_linter","title":"Missing argument linter — missing_argument_linter","text":"Check missing arguments function calls (e.g. stats::median(1:10, )).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing argument linter — missing_argument_linter","text":"","code":"missing_argument_linter( except = c(\"alist\", \"quote\", \"switch\"), allow_trailing = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Missing argument linter — missing_argument_linter","text":"except character vector function names exceptions. allow_trailing always allow trailing empty arguments?","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing argument linter — missing_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing argument linter — missing_argument_linter","text":"","code":"# will produce lints lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter() ) #> ::warning file=,line=1,col=15::file=,line=1,col=15,[missing_argument_linter] Missing argument in function call. # okay lint( text = 'tibble(x = \"a\")', linters = missing_argument_linter() ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(except = \"tibble\") ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(allow_trailing = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing package linter — missing_package_linter","title":"Missing package linter — missing_package_linter","text":"Check missing packages library(), require(), loadNamespace(), requireNamespace() calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing package linter — missing_package_linter","text":"","code":"missing_package_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing package linter — missing_package_linter","text":"common_mistakes, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing package linter — missing_package_linter","text":"","code":"# will produce lints lint( text = \"library(xyzxyz)\", linters = missing_package_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[missing_package_linter] Package 'xyzxyz' is not installed. # okay lint( text = \"library(stats)\", linters = missing_package_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify lintr defaults — modify_defaults","title":"Modify lintr defaults — modify_defaults","text":"Modify list defaults name, allowing replacement, deletion addition new elements.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify lintr defaults — modify_defaults","text":"","code":"modify_defaults(defaults, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify lintr defaults — modify_defaults","text":"defaults named list elements modify. ... arguments elements change. unnamed, argument automatically named. named argument already exists defaults, replaced new element. exist, added. value NULL, element removed.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify lintr defaults — modify_defaults","text":"modified list elements, sorted name. achieve sort platform-independent way, two transformations applied names: (1) replace _ 0 (2) convert tolower().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Modify lintr defaults — modify_defaults","text":"","code":"# custom list of undesirable functions: # remove `sapply` (using `NULL`) # add `cat` (with an accompanying message), # add `print` (unnamed, i.e. with no accompanying message) # add `source` (as taken from `all_undesirable_functions`) my_undesirable_functions <- modify_defaults( defaults = default_undesirable_functions, sapply = NULL, \"cat\" = \"No cat allowed\", \"print\", all_undesirable_functions[[\"source\"]] ) # list names of functions specified as undesirable names(my_undesirable_functions) #> [1] \".libPaths\" \"attach\" \"browser\" \"cat\" #> [5] \"debug\" \"debugcall\" \"debugonce\" \"detach\" #> [9] \"library\" \"mapply\" \"options\" \"par\" #> [13] \"print\" \"require\" \"setwd\" \"sink\" #> [17] \"source\" \"Sys.setenv\" \"Sys.setlocale\" \"trace\" #> [21] \"undebug\" \"untrace\""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Namespace linter — namespace_linter","title":"Namespace linter — namespace_linter","text":"Check missing packages symbols namespace calls. Note using check_exports=TRUE check_nonexports=TRUE load packages used user code potentially change global state.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Namespace linter — namespace_linter","text":"","code":"namespace_linter(check_exports = TRUE, check_nonexports = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Namespace linter — namespace_linter","text":"check_exports Check symbol exported namespace namespace::symbol calls. check_nonexports Check symbol exists namespace namespace:::symbol calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Namespace linter — namespace_linter","text":"configurable, correctness, executing, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Namespace linter — namespace_linter","text":"","code":"# will produce lints lint( text = \"xyzxyz::sd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[namespace_linter] Package 'xyzxyz' is not installed. lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[namespace_linter] 'ssd' is not exported from {stats}. # okay lint( text = \"stats::sd(c(1, 2, 3))\", linters = namespace_linter() ) lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter(check_exports = FALSE) ) lint( text = \"stats:::ssd(c(1, 2, 3))\", linters = namespace_linter(check_nonexports = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of nested ifelse() calls — nested_ifelse_linter","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Calling ifelse() nested calls problematic two main reasons: can hard read -- mapping code expected output code can messy task/require lot mental bandwidth, especially code nests inefficient -- ifelse() can evaluate arguments yes (see https://stackoverflow.com/q/16275149); issue exacerbated nested calls","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"nested_ifelse_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Users can instead rely readable alternative modeled SQL CASE statements, data.table::fcase() dplyr::case_when(), use look---merge approach (build mapping table values outputs merge input).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"# will produce lints lint( text = 'ifelse(x == \"a\", 1L, ifelse(x == \"b\", 2L, 3L))', linters = nested_ifelse_linter() ) #> ::warning file=,line=1,col=22::file=,line=1,col=22,[nested_ifelse_linter] Don't use nested ifelse() calls; instead, try (1) data.table::fcase; (2) dplyr::case_when; or (3) using a lookup table. # okay lint( text = 'dplyr::case_when(x == \"a\" ~ 1L, x == \"b\" ~ 2L, TRUE ~ 3L)', linters = nested_ifelse_linter() ) lint( text = 'data.table::fcase(x == \"a\", 1L, x == \"b\", 2L, default = 3L)', linters = nested_ifelse_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Non-portable path linter — nonportable_path_linter","title":"Non-portable path linter — nonportable_path_linter","text":"Check file.path() used construct safe portable paths.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Non-portable path linter — nonportable_path_linter","text":"","code":"nonportable_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Non-portable path linter — nonportable_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Non-portable path linter — nonportable_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":null,"dir":"Reference","previous_headings":"","what":"Normalize lint exclusions — normalize_exclusions","title":"Normalize lint exclusions — normalize_exclusions","text":"Normalize lint exclusions","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Normalize lint exclusions — normalize_exclusions","text":"","code":"normalize_exclusions(x, normalize_path = TRUE, root = getwd(), pattern = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Normalize lint exclusions — normalize_exclusions","text":"x Exclusion specification character vector filenames directories relative root named list integers specifying lines excluded per file named list named lists specifying linters lines excluded linters per file. normalize_path names returned exclusion list normalized paths? , relative root. root Base directory relative filename resolution. pattern non-NULL, exclude files excluded directories match pattern. Passed list.files directory excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Normalize lint exclusions — normalize_exclusions","text":"named list file exclusions. names list specify filenames excluded. file exclusion possibly named list containing line numbers exclude, sentinel Inf completely excluded files. entry named, exclusions take effect linter name. normalize_path TRUE, file names normalized relative root. Otherwise paths left provided (relative root absolute).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":".1 0.1 mean thing, latter easier read due small size '.' glyph.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"","code":"numeric_leading_zero_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"","code":"# will produce lints lint( text = \"x <- .1\", linters = numeric_leading_zero_linter() ) #> ::warning file=,line=1,col=6::file=,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/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. 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_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/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] There should be 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_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_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):","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)"},{"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.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/paste_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Raise lints for several common poor usages of paste() — paste_linter","text":"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":[]},{"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 = \"\"). # 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() )"},{"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_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] `%>%` should always have a space before it 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] `|>` should always have a space before it 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/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.","code":""},{"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 conjunct_test_linter consecutive_assertion_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 implicit_assignment_linter indentation_linter infix_spaces_linter inner_combine_linter is_numeric_linter lengths_linter line_length_linter matrix_apply_linter nested_ifelse_linter numeric_leading_zero_linter object_length_linter object_usage_linter outer_negation_linter paren_body_linter pipe_call_linter pipe_continuation_linter quotes_linter redundant_equals_linter semicolon_linter sort_linter spaces_inside_linter spaces_left_parentheses_linter string_boundary_linter system_file_linter T_and_F_symbol_linter unnecessary_concatenation_linter unnecessary_lambda_linter unnecessary_nested_if_linter unnecessary_placeholder_linter unreachable_code_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_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","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/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 routine_registration_linter seq_linter strings_as_factors_linter T_and_F_symbol_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/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/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] Trailing semicolons are not needed. lint( text = \"a <- 1; b <- 1\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[semicolon_linter] Compound semicolons are discouraged. Replace them 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] Compound semicolons are discouraged. Replace them 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] seq(length(...)) is likely to be wrong in the empty edge case. Use seq_along(...) instead. lint( text = \"1:nrow(x)\", linters = seq_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[seq_linter] 1:nrow(...) is likely to be wrong in the empty edge case. Use seq_len(nrow(...)) instead. lint( text = \"dplyr::mutate(x, .id = 1:n())\", linters = seq_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[seq_linter] 1:n() is likely to be wrong in the empty edge case. Use seq_len(n()) instead. # 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":"Require usage of sort() over .[order(.)] — sort_linter","title":"Require usage of sort() over .[order(.)] — sort_linter","text":"sort() dedicated option sort list vector. legible around twice fast .[order(.)], gap performance growing vector size.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of sort() over .[order(.)] — sort_linter","text":"","code":"sort_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of sort() over .[order(.)] — 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":"Require usage of sort() over .[order(.)] — 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)]. 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)]. # okay lint( text = \"x[sample(order(x))]\", linters = sort_linter() ) lint( text = \"y[order(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/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","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] This code relies on the default value of stringsAsFactors, which changed in version R 4.0. Please supply an explicit value for stringsAsFactors for this code to work with versions of R both before and after this switch. # 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 consecutive_assertion_linter cyclocomp_linter extraction_operator_linter function_argument_linter function_left_parentheses_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter line_length_linter numeric_leading_zero_linter object_length_linter object_name_linter object_usage_linter package_hooks_linter paren_body_linter pipe_call_linter pipe_continuation_linter quotes_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/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\"))"},{"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 strings identify 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 # TODO\", linters = todo_comment_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[todo_comment_linter] TODO comments should be removed. lint( text = \"pi <- 1.0 # FIXME\", linters = todo_comment_linter() ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[todo_comment_linter] TODO comments should be removed. lint( text = \"x <- TRUE # hack\", linters = todo_comment_linter(todo = c(\"todo\", \"fixme\", \"hack\")) ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[todo_comment_linter] TODO comments should be removed. # 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() )"},{"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 <- withr::local_tempfile(lines = \"x <- 1\\n\") readLines(f) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f77a53bae0': No such file or directory #> Error in file(con, \"r\"): cannot open the connection lint( filename = f, linters = trailing_blank_lines_linter() ) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f77a53bae0': No such file or directory #> Error in file(con, \"r\"): cannot open the connection # okay f <- withr::local_tempfile(lines = \"x <- 1\") readLines(f) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f74e77bb3d': No such file or directory #> Error in file(con, \"r\"): cannot open the connection lint( filename = f, linters = trailing_blank_lines_linter() ) #> Warning: cannot open file '/tmp/Rtmpa82qdv/file16f74e77bb3d': No such file or directory #> Error in file(con, \"r\"): cannot open the connection"},{"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] Trailing whitespace is superfluous. 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] Trailing whitespace is superfluous. # 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 (e.g. base::return(), base::options(), base::sapply()) 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] \"Sys.setenv\" \"Sys.setlocale\" \"trace\" \"undebug\" #> [21] \"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] Function \"sapply\" is undesirable. 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] Function \"log10\" is undesirable. 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] Function \"log10\" is undesirable. 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] Function \"dir\" is undesirable. # 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] Operator `<<-` is undesirable. 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] Operator `$` is undesirable. 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] Unneeded concatenation without arguments. Replace the \"c\" call 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] Unneeded concatenation of a constant. Remove the \"c\" call. 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] Unneeded concatenation of a simple expression. Remove the \"c\" call, replacing with \"as.vector\" if using \"c\" to string 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()"},{"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, 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)). # 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() )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"Avoid unnecessary nested conditional statements","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"","code":"unnecessary_nested_if_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"","code":"# will produce lints 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_nested_if_linter() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[unnecessary_nested_if_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) { ... }`. # okay writeLines(\"if (x && y) { \\n return(1L) \\n}\") #> if (x && y) { #> return(1L) #> } lint( text = \"if (x && y) { \\n return(1L) \\n}\", linters = unnecessary_nested_if_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_nested_if_linter() )"},{"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 top-level return() stop() 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()"},{"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, 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] Code and comments coming after a top-level return() or stop() should be removed. # 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() )"},{"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\") )"},{"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 loading . except_packages Character vector packages ignored. usually attached side effects.","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] Package 'dplyr' 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 linters_with_tags().","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, 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] Conditional expressions require scalar logical operators (&& and ||) 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] Conditional expressions require scalar logical operators (&& and ||) # okay lint( text = \"if (TRUE && FALSE) 1\", linters = vector_logic_linter() ) lint( text = \"if (TRUE && (TRUE || FALSE)) 4\", linters = vector_logic_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/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, 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] Tests should compare objects 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] Tests should compare objects 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":".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-development-version","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr (development version)","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). 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-development-version","dir":"Changelog","previous_headings":"","what":"Changes to defaults","title":"lintr (development version)","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-development-version","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr (development version)","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-development-version","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr (development version)","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-development-version","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr (development version)","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) object_usage_linter() gives helpful warning glue() expression fails evaluate (#1985, @MichaelChirico)","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 syntatic 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 james.f.hester@gmail.com. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with lintr","title":"Getting help with lintr","text":"Thanks using lintr. filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"making-a-reproducible-example","dir":"","previous_headings":"","what":"Making a reproducible example","title":"Getting help with lintr","text":"Start making minimal reproducible example using reprex package. use reprex effectivly, check Get help! section tidyverse site. useful function create reprexes lintr issues lint(). can include code doesn’t lint expected linter question. example, code question contains characters need escaped, consider using raw strings instead save headache figuring multiple levels escapes.","code":"library(lintr) lint( text = \"x = 1\", linters = assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"asking-for-help","dir":"","previous_headings":"","what":"Asking for help","title":"Getting help with lintr","text":"Armed reprex, next step figure ask. ’s clarification question (e.g. don’t know exclude certain files lint workflow), start community.rstudio.com, /StackOverflow. people answer questions.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"filing-an-issue","dir":"","previous_headings":"","what":"Filing an issue","title":"Getting help with lintr","text":"’s bug, can create issue reprex. ’s false positive false negative lint, can either create issue reprex lintr repository, discuss underlying style guide respective repository. opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed. Thanks help!","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions","dir":"Articles","previous_headings":"For packages","what":"GitHub Actions","title":"Continuous integration","text":"package GitHub, easiest way GitHub Actions. workflow configuration files use YAML syntax. usethis package great functionality can help workflow files. straightforward way add lintr workflow package use r-lib/actions’s lint example. usethis, need call create workflow file called lint.yaml place correct location, namely .github/workflows directory repository. file configures steps required run lintr::lint_package() package. Alternatively can use eponymous lint-changed-files.yaml lint changed files: Comments commit pull request printed annotations along side status check GitHub. want builds produce error instead just warning, can set environment variable LINTR_ERROR_ON_LINT=true. set default r-lib/actions’s lint.yaml lint-changed-files.yaml. Note kill R process case lint. project subdirectory like use GitHub Actions annotations, can set options(lintr.github_annotation_project_dir = \"path//project\") make sure annotations point correct paths.","code":"usethis::use_github_action(\"lint\") usethis::use_github_action(\"lint-changed-files\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"travis-ci","dir":"Articles","previous_headings":"For packages","what":"Travis CI","title":"Continuous integration","text":"want run lintr Travis-CI, need Travis install package first. can done adding following line .travis.yml recommend running lintr::lint_package() after_success step build process: lints found commit pull request printed Travis-CI. environment variable LINTR_ERROR_ON_LINT mentioned GitHub actions also works Travis CI builds.","code":"r_github_packages: - r-lib/lintr after_success: - R CMD INSTALL $PKG_TARBALL - Rscript -e 'lintr::lint_package()'"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"for-projects","dir":"Articles","previous_headings":"","what":"For projects","title":"Continuous integration","text":"limited using lintr packages – can use combination continuous integration project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions-1","dir":"Articles","previous_headings":"For projects","what":"GitHub Actions","title":"Continuous integration","text":"project GitHub, take advantage GitHub Actions usethis functionality. r-lib/actions includes lint-project example, can use calling:","code":"usethis::use_github_action(\"lint-project\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"super-linter","dir":"Articles","previous_headings":"For projects","what":"Super-Linter","title":"Continuous integration","text":"lintr powers R lints Super-Linter MegaLinter, provide unified linting experience across many languages. Specifically, execute lintr::lint() R R Markdown files included given project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-the-linter","dir":"Articles","previous_headings":"","what":"Writing the linter","title":"Creating new linters","text":"Describe linter, giving title briefly covering usages discouraged linter active. lines (1) generate Tags section documentation linter1; (2) link full table available linters; (3) mark function export. unfamiliar probably (1), can skipped outside lintr . Next, define name new linter. convention suffix linter names _linter. _linter functions function factories return closure actual linting function. define additional parameters useful linter function declaration (see, e.g. assignment_linter), pipe_call_linter requires additional arguments. core linter logic. xpath XPath expression expressions matching discouraged usage. xpath saved inside factory code (opposed inside linter ) efficiency. Often, xpath somewhat complicated / involve assembly code using paste() glue::glue()[^See infix_spaces_linter() example ], case preferable execute code creating linter; cached XPath re-used expression file linter run. Let’s examine XPath bit closely: Taken together, means want match expr nodes preceded %>% infix operator whose first child node name. maps pretty closely description pipe_call_linter looking , subtlety mapping R code ’re used show XML representation. expr nodes particular take practice get accustomed – use plentiful XPath-based linters lintr guide get extra practice2. Note: xml2 implements XPath 1.0, lacks helpful features available XPath 2.0. closure. called source_expression variable contains top level expressions file linted. call Linter() gives closure class ‘linter’ (also guesses name linter; see ?Linter details). raw text expression available source_file$content. However, generally possible implement linters raw text – consider equals_na_linter. just look == NA text file, ’ll generate many false positives, e.g. comments (# note: .na() proper way check == NA) inside character literals (warning(\"use == NA check missingness\")). ’re also likely generate false negatives, example == NA appear different lines! Working around issues using un-parsed text every situation amounts re-implementing parser. Therefore recommended work tokens source_file$parsed_content source_file$xml_parsed_content, tokenized R parser. tokens obtained parse() utils::getParseData() calls done prior calling new linter. getParseData() returns data.frame information source parse tree file linted. list tokens available r-source/src/main/gram.y. source_file$xml_parsed_content uses xmlparsedata::xml_parse_data() convert getParseData() output XML tree, enables writing linter logic XPath, powerful language expressing paths within nested XML data structure. linters lintr built using XPath powerful language computation abstract syntax tree / parse tree. , return early source_expression expression-level object. get_source_expression() returns object parses input file two ways – done expression--expression, contains expressions file. done facilitate caching. Suppose package long source file (e.g., 100s expressions) – rather run linters every expression every time file updated, caching activated lintr run linter expressions changed. Therefore, preferable write expression-level linters whenever possible. Two types exceptions observed lintr (1) several expressions required ensure linter logic applies (e.g., conjunct_test_linter looks consecutive calls stopifnot(), typically appear consecutive expressions) (2) linter logic simple & fast compute, overhead re-running linter low (e.g., single_quotes_linter). cases, use is_lint_level(source_expression, \"file\"). source_expression$xml_parsed_content copied local variable (strictly necessary facilitates debugging). xml2::xml_find_all() used execute XPath particular expression. Keep mind typically possible single expression generate one lint – example, x %>% na.omit %>% sum trigger pipe_call_linter() twice3. Finally, pass matching XML node(s) xml_nodes_to_lints(), returns Lint objects corresponding “bad” usages found source_expression. See ?Lint ?xml_nodes_to_lints details arguments. Note , message lint always , many linters, message customized closely match observed usage. cases, xml_nodes_to_lint() can conveniently accept function lint_message takes node input converts customized message. See, example, seq_linter.","code":"#' Pipe call linter #' #' Force explicit calls in magrittr pipes, e.g., #' `1:3 %>% sum()` instead of `1:3 %>% sum`. #' @evalRd rd_tags(\"pipe_call_linter\") #' @seealso [linters] for a complete list of linters available in lintr. #' @export pipe_call_linter <- function() { xpath <- \"//expr[preceding-sibling::SPECIAL[text() = '%>%'] and *[1][self::SYMBOL]]\" //expr # global search (//) for 'expr' nodes (R expressions), at any nesting level [ # node[...] looks for any 'node' satisfying conditions in ... preceding-sibling:: # \"siblings\" are at the same nesting level in XML SPECIAL[ # 'SPECIAL' is the parse token for infix operators like %% or %+% text() = '%>%' # text() returns the string associated with this node ] # and # combine conditions with 'and' * # match any node [1] # match the first such node [self::SYMBOL] # match if the current node is a 'SYMBOL' (i.e., a 'name' in R) ] # Linter(function(source_expression) { if (!is_lint_level(source_expression, \"expression\")) { return(list()) } xml <- source_expression$xml_parsed_content bad_expr <- xml2::xml_find_all(xml, xpath) xml_nodes_to_lints( bad_expr, source_expression = source_expression, lint_message = \"Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`.\", type = \"warning\" )"},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-linter-tests","dir":"Articles","previous_headings":"","what":"Writing linter tests","title":"Creating new linters","text":"(NB: section uses assignment_linter() simpler examples pipe_continuation_linter().) lintr works best inside testthat unit testing framework, particular, lintr exports lintr::expect_lint() designed companion testthat expectations. can define tests inside separate test_that calls. linters use default form. test series expectations linter using expect_lint. Please see ?expect_lint full description parameters. main three aspects test : Linter returns lints nothing lint, e.g. Linter returns lint something lint, e.g. many edge cases can think might break , e.g. may want test additional lint attributes correct, type, line number, column number, e.g. Finally, good idea test linter reports multiple lints needed, e.g. always better write many tests rather .","code":"test_that(\"returns the correct linting\", { expect_lint(\"blah\", NULL, assignment_linter()) expect_lint(\"blah=1\", rex(\"Use <-, not =, for assignment.\"), assignment_linter() ) expect_lint(\"fun((blah = fun(1)))\", rex(\"Use <-, not =, for assignment.\"), assignment_linter() ) expect_lint(\"blah=1\", list(message = \"assignment\", line_number = 1, column_number = 5, type = \"style\"), assignment_linter() ) expect_lint(\"blah=1; blah=2\", list( list(line_number = 1, column_number = 5), list(line_number = 1, column_number = 13), ) assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"other-utilities-for-writing-custom-linters","dir":"Articles","previous_headings":"","what":"Other utilities for writing custom linters","title":"Creating new linters","text":"Besides is_lint_level(), lintr also exports helpers generally useful writing custom linters; used lot internals helpers, ’ve tested demonstrated utility already. get_r_string(): Whenever linter needs examine value character literal (e.g., whether argument value set string), use extract string exactly R see . especially important make logic robust R-4-style raw strings like R\"-(hello)-\", otherwise difficult express, example XPath.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"more-details-about-writing-tests-for-new-lintr-linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"More details about writing tests for new {lintr} linters","title":"Creating new linters","text":"lintr package uses testthat testing. can run currently available tests using devtools::test(). want run tests given file use filter argument devtools::test(). Linter tests put tests/testthat/ folder. test filename linter name prefixed test-, e.g. test-pipe_continuation_linter.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"adding-your-linter-to-the-default_linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Adding your linter to the default_linters","title":"Creating new linters","text":"linter implements part tidyverse style guide can add default_linters. object created file zzz.R (name ensures always run linters defined). Add linter name default_linters list NULL end, add corresponding test case test script ./tests/testthat/default_linter_testcode.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"submit-pull-request","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Submit pull request","title":"Creating new linters","text":"Push changes branch fork lintr repository, submit pull request get linter merged lintr!","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"rstudio","dir":"Articles","previous_headings":"","what":"RStudio","title":"Editor setup","text":"lintr lints automatically displayed RStudio Markers pane (RStudio versions > v0.99.206). RStudio Example order show “Markers” pane RStudio: Menu “Tools” -> “Global Options…”, window title “Options” pop . window: click “Code” left; click “Diagnostics” tab; check “Show diagnostics R”. lint source file test.R type Console lintr::lint(\"test.R\") look result “Markers” pane. package also includes two addins linting current source package. bind addin keyboard shortcut navigate Tools > addins > Browse Addins > Keyboard Shortcuts. ’s recommended use Alt+Shift+L linting current source lint Ctrl+Shift+Alt+L code package. easy remember Alt+Shift+L(int) ;)","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"emacs","dir":"Articles","previous_headings":"","what":"Emacs","title":"Editor setup","text":"lintr built-integration flycheck versions greater 0.23.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation","dir":"Articles","previous_headings":"Emacs","what":"Installation","title":"Editor setup","text":"lintr fully integrated flycheck using ESS. See installation documentation packages information.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration","dir":"Articles","previous_headings":"Emacs","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff. - M-x customize-option -> flycheck-lintr-linters -> linters_with_defaults(line_length_linter(120))","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---syntastic","dir":"Articles","previous_headings":"","what":"Vim - syntastic","title":"Editor setup","text":"lintr can integrated syntastic --fly linting. Vim Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Installation","title":"Editor setup","text":"Put file syntastic/lintr.vim syntastic/syntax_checkers/r. using pathogen directory ~/.vim/bundles/syntastic/syntax_checkers/r. also need add following lines .vimrc.","code":"let g:syntastic_enable_r_lintr_checker = 1 let g:syntastic_r_checkers = ['lintr']"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff.","code":"let g:syntastic_r_lintr_linters = \"linters_with_defaults(line_length_linter(120))\""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---ale","dir":"Articles","previous_headings":"","what":"Vim - ALE","title":"Editor setup","text":"lintr can integrated ALE fly linting.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Installation","title":"Editor setup","text":"lintr integrated ALE requires additional installation.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Configuration","title":"Editor setup","text":"can configure linters used, e.g. using different line length cutoff. can also configure whether lint lint_package used. Set 1 lint_package 0 (default) lint. See :h ale_r_lintr information. Note configuration .lintr files supported. work around can used read contents .lintr file root working directory. allow use configuration .lintr files.","code":"let g:ale_r_lintr_options = \"linters_with_defaults(line_length_linter(120))\" let g:ale_r_lintr_lint_package = 1 if filereadable(\".lintr\") let g:ale_r_lintr_options = join(readfile('.lintr')) endif"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"sublime-text-3","dir":"Articles","previous_headings":"","what":"Sublime Text 3","title":"Editor setup","text":"lintr can integrated Sublime Linter --fly linting. Sublime Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Installation","title":"Editor setup","text":"Simply install sublimeLinter-contrib-lintr using Package Control. information see Sublime Linter Docs","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. disabling assignment linter using different line length cutoff. SublimeLinter User Settings","code":"{ \"linters\": { \"lintr\": { \"linters\": \"linters_with_defaults(assignment_linter = NULL, line_length_linter(120))\" } } }"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"atom","dir":"Articles","previous_headings":"","what":"Atom","title":"Editor setup","text":"lintr can integrated Linter fly linting. Atom Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-4","dir":"Articles","previous_headings":"Atom","what":"Installation","title":"Editor setup","text":"Simply install linter-lintr within Atom command line : information bug reports see Atom linter-lintr.","code":"apm install linter-lintr"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"visual-studio-code","dir":"Articles","previous_headings":"","what":"Visual Studio Code","title":"Editor setup","text":"Visual Studio Code, vscode-R presents lintr diagnostics languageserver. VS Code Example","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-5","dir":"Articles","previous_headings":"Visual Studio Code","what":"Installation","title":"Editor setup","text":"Installing languageserver package R vscode-R extension VS Code enable lintr VS Code default run following command lines:","code":"Rscript -e 'install.packages(\"languageserver\")' code --install-extension reditorsupport.r"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"running-lintr-on-a-project","dir":"Articles","previous_headings":"","what":"Running lintr on a project","title":"Using lintr","text":"Checking R project lints can done three different functions: Lint single file using lint(): Lint directory using lint_dir(): apply lint() R source files matching pattern argument. default, means .R files well knitr formats (e.g. .Rmd, .Rnw). lint_dir vectorized path, multiple directories can linted time. Lint relevant directories R package using lint_package(): apply lint_dir() subdirectories usually containing R code packages: R containing package implementation. tests containing test code. inst containing sample code vignettes installed along package. vignettes containing package vignettes. data-raw containing code produce data files. information assumed package structure, see R Packages.","code":"lint(filename = \"R/bad.R\") lint_dir(path = \"R\") lint_package(path = \".\")"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"the--lintr-file","dir":"Articles","previous_headings":"Configuring linters","what":"The .lintr file","title":"Using lintr","text":"canonical way configure R projects packages linting create .lintr file project root. file debian control format (?read.dcf), value evaluated R code lintr reading settings. minimal .lintr file can generated running use_lintr() project directory. Lintr supports per-project configuration following fields. linters - see ?linters_with_defaults example specifying non-default linters ?linters_with_tags fine-grained control. exclusions - list filenames exclude linting. can use named item exclude certain lines file. exclude - regex pattern lines exclude linting. Default “# nolint” exclude_start - regex pattern start exclusion range. Default “# nolint start” exclude_end - regex pattern end exclusion range. Default “# nolint end” encoding - encoding used source files. Default inferred .Rproj DESCRIPTION files, fallback UTF-8","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"lintr-file-example","dir":"Articles","previous_headings":"Configuring linters","what":".lintr File Example","title":"Using lintr","text":"example .lintr file uses 120 character line lengths, disables commented_code_linter, excludes couple files.","code":"linters: linters_with_defaults( line_length_linter(120), commented_code_linter = NULL ) exclusions: list( \"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\", \"tests/testthat/exclusions-test\" )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"other-configuration-options","dir":"Articles","previous_headings":"Configuring linters","what":"Other configuration options","title":"Using lintr","text":"generally, lintr searches settings file according following prioritized list. first one found, , used: options(\"lintr.linter_file\") absolute path, file used. default option \".lintr\" value environment variable R_LINTR_LINTER_FILE, set. linter file (, file named like lintr.linter_file) currently-searched directory, .e. directory file passed lint(); linter file .github/linters child directory currently-searched directory. project-local linter file closest parent directory currently-searched directory, starting deepest path, moving upwards one level time. run lint_package(), directory can differ linted file. linter file user’s HOME directory. linter file called config user’s configuration path (given tools::R_user_dir(\"lintr\", = \"config\")). linter file found, default settings take effect (see defaults).","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-options","dir":"Articles","previous_headings":"Configuring linters","what":"Using options()","title":"Using lintr","text":"Values options(), NULL, take precedence linter file (e.g. .lintr). Note key option_name linter file translates R option lintr.option_name. example, options(lintr.exclude = \"# skip lint\") take precedence exclude: # nolint linter file.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-arguments-to-lint","dir":"Articles","previous_headings":"Configuring linters","what":"Using arguments to lint()","title":"Using lintr","text":"settings can also passed arguments linting functions directly. case exclusions, combined globally parsed settings. settings overridden. specified settings changed, remaining settings taken directly defaults, argument parse_settings = FALSE can added function calls. suppress reading .lintr configuration. particularly useful tests exclude example files containing lints package-level .lintr excludes files lints intentional.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"defaults","dir":"Articles","previous_headings":"Configuring linters","what":"Defaults","title":"Using lintr","text":"default settings lintr intended conform tidyverse style guide. However, behavior can customized using different methods. Apart lintr.linter_file, defaults \".lintr\", following settings: Note default encoding setting depends file linted. Encoding found .Rproj file DESCRIPTION file, encoding overrides default UTF-8.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"customizing-active-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Customizing active linters","title":"Using lintr","text":"want customize linters, can use helper function linters_with_defaults(), keep unnamed linters default settings. Disable linter passing NULL. example, set line length limit 120 characters globally disable whitespace_linter(), can put .lintr: default, following linters enabled. applicable, default settings also shown. Another way customize linters specifying tags linters_with_tags(). available tags listed : can select tags interest see linters included: can include tag-based linters configuration file, customize :","code":"linters: linters_with_defaults( line_length_linter = line_length_linter(120L), whitespace_linter = NULL ) lintr::available_tags(packages = \"lintr\") #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"readability\" \"robustness\" #> [13] \"style\" linters <- lintr::linters_with_tags(tags = c(\"package_development\", \"readability\")) names(linters) #> [1] \"backport_linter\" \"boolean_arithmetic_linter\" #> [3] \"brace_linter\" \"commas_linter\" #> [5] \"commented_code_linter\" \"conjunct_test_linter\" #> [7] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [9] \"empty_assignment_linter\" \"expect_comparison_linter\" #> [11] \"expect_identical_linter\" \"expect_length_linter\" #> [13] \"expect_named_linter\" \"expect_not_linter\" #> [15] \"expect_null_linter\" \"expect_s3_class_linter\" #> [17] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [19] \"expect_type_linter\" \"fixed_regex_linter\" #> [21] \"for_loop_index_linter\" \"function_left_parentheses_linter\" #> [23] \"function_return_linter\" \"implicit_assignment_linter\" #> [25] \"indentation_linter\" \"infix_spaces_linter\" #> [27] \"inner_combine_linter\" \"is_numeric_linter\" #> [29] \"lengths_linter\" \"line_length_linter\" #> [31] \"matrix_apply_linter\" \"nested_ifelse_linter\" #> [33] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [35] \"object_usage_linter\" \"outer_negation_linter\" #> [37] \"package_hooks_linter\" \"paren_body_linter\" #> [39] \"pipe_call_linter\" \"pipe_continuation_linter\" #> [41] \"quotes_linter\" \"redundant_equals_linter\" #> [43] \"semicolon_linter\" \"sort_linter\" #> [45] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [47] \"string_boundary_linter\" \"system_file_linter\" #> [49] \"T_and_F_symbol_linter\" \"unnecessary_concatenation_linter\" #> [51] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [53] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [55] \"yoda_test_linter\" linters: linters_with_tags( tags = c(\"package_development\", \"readability\"), yoda_test_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-all-available-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Using all available linters","title":"Using lintr","text":"default lintr configuration includes linters relevant tidyverse style guide, many linters available lintr. can see list available linters using want use available linters, can include .lintr file: want use available linters except , can exclude using NULL:","code":"names(lintr::all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"condition_message_linter\" \"conjunct_test_linter\" #> [13] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [15] \"duplicate_argument_linter\" \"empty_assignment_linter\" #> [17] \"equals_na_linter\" \"expect_comparison_linter\" #> [19] \"expect_identical_linter\" \"expect_length_linter\" #> [21] \"expect_named_linter\" \"expect_not_linter\" #> [23] \"expect_null_linter\" \"expect_s3_class_linter\" #> [25] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [27] \"expect_type_linter\" \"extraction_operator_linter\" #> [29] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [31] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [33] \"function_return_linter\" \"ifelse_censor_linter\" #> [35] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [37] \"indentation_linter\" \"infix_spaces_linter\" #> [39] \"inner_combine_linter\" \"is_numeric_linter\" #> [41] \"lengths_linter\" \"line_length_linter\" #> [43] \"literal_coercion_linter\" \"matrix_apply_linter\" #> [45] \"missing_argument_linter\" \"missing_package_linter\" #> [47] \"namespace_linter\" \"nested_ifelse_linter\" #> [49] \"nonportable_path_linter\" \"numeric_leading_zero_linter\" #> [51] \"object_length_linter\" \"object_name_linter\" #> [53] \"object_usage_linter\" \"outer_negation_linter\" #> [55] \"package_hooks_linter\" \"paren_body_linter\" #> [57] \"paste_linter\" \"pipe_call_linter\" #> [59] \"pipe_continuation_linter\" \"quotes_linter\" #> [61] \"redundant_equals_linter\" \"redundant_ifelse_linter\" #> [63] \"regex_subset_linter\" \"routine_registration_linter\" #> [65] \"semicolon_linter\" \"seq_linter\" #> [67] \"sort_linter\" \"spaces_inside_linter\" #> [69] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [71] \"string_boundary_linter\" \"strings_as_factors_linter\" #> [73] \"system_file_linter\" \"T_and_F_symbol_linter\" #> [75] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [77] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [79] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [81] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [83] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [85] \"unused_import_linter\" \"vector_logic_linter\" #> [87] \"whitespace_linter\" \"yoda_test_linter\" linters: all_linters() linters: all_linters( commented_code_linter = NULL, implicit_integer_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"advanced-programmatic-retrieval-of-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Advanced: programmatic retrieval of linters","title":"Using lintr","text":"use cases, may useful specify linters string instead name, .e. \"assignment_linter\" instead writing assignment_linter(). Beware cases, simple get() enough:","code":"library(lintr) #> #> Attaching package: 'lintr' #> The following object is masked _by_ '.GlobalEnv': #> #> default_settings linter_name <- \"assignment_linter\" withr::with_tempfile(\"tmp\", { writeLines(\"a = 1\", tmp) # linter column is just 'get' print(as.data.frame(lint(tmp, linters = get(linter_name)()))) this_linter <- get(linter_name)() attr(this_linter, \"name\") <- linter_name # linter column is 'assignment_linter' print(as.data.frame(lint(tmp, linters = this_linter))) # more concise alternative: use eval(call(.)) print(as.data.frame(lint(tmp, linters = eval(call(linter_name))))) }) #> filename line_number column_number type #> 1 /tmp/Rtmp9oQt7d/file1e0964c795c9 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 get #> filename line_number column_number type #> 1 /tmp/Rtmp9oQt7d/file1e0964c795c9 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter #> filename line_number column_number type #> 1 /tmp/Rtmp9oQt7d/file1e0964c795c9 1 3 style #> message line linter #> 1 Use <-, not =, for assignment. a = 1 assignment_linter"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"exclusions","dir":"Articles","previous_headings":"","what":"Exclusions","title":"Using lintr","text":"Sometimes, linters globally disabled. Instead, one might want exclude code linting altogether selectively disable linters part code. Note preferred way excluding lints source code use narrowest possible scope specify exactly linters throw lint marked line. prevents accidental suppression justified lints happen line lint needs suppressed.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-of-code","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines of code","title":"Using lintr","text":"Within source files, special comments can used exclude single lines code linting. lints produced marked line excluded results. default, special comment # nolint: file.R > lint(\"file.R\") file2.R > lint(\"file2.R\") Observe lints suppressed output shown. Sometimes, specific linter needs excluded. case, name linter can appended # nolint comment preceded colon terminated dot.","code":"X = 42L # -------------- this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. X = 42L # nolint ------ this comment overflows the default 80 chars line length."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-only-some-linters","dir":"Articles","previous_headings":"Exclusions","what":"Excluding only some linters","title":"Using lintr","text":"file3.R > lint(\"file3.R\") Observe object_name_linter suppressed. preferable blanket # nolint statements blanket exclusions may accidentally silence linter intentionally suppressed. Multiple linters can specified listing comma separator: file4.R > lint(\"file4.R\") can also specify linter names unique prefix instead full name: file5.R > lint(\"file5.R\")","code":"X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-multiple-lines-of-codes","dir":"Articles","previous_headings":"Exclusions","what":"Excluding multiple lines of codes","title":"Using lintr","text":"linters disabled contiguous block code, exclude_start exclude_end patterns can used. default # nolint start # nolint end respectively. # nolint start accepts syntax # nolint disable specific linters following lines # nolint end encountered. (lints)","code":"# x <- 42L # print(x) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Commented code should be removed. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[commented_code_linter] Commented code should be removed. # nolint start: commented_code_linter. # x <- 42L # print(x) # nolint end"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-via-the-config-file","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines via the config file","title":"Using lintr","text":"Individual lines can also excluded via config file setting key exclusions list elements corresponding different files. exclude lints line 1 file R/bad.R line_length_linter lines 4 6 file, one can set paths interpreted relative location .lintr file.","code":"exclusions: list( \"R/bad.R\" = list( 1, # global exclusions are unnamed line_length_linter = 4:6 ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-files-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding files completely","title":"Using lintr","text":"linter configuration can also used exclude file entirely, linter file entirely. Use sentinel line number Inf mark lines excluded within file. file given character vector, full exclusion implied.","code":"exclusions: list( # excluded from all lints: \"R/excluded1.R\", \"R/excluded2.R\" = Inf, \"R/excluded3.R\" = list(Inf), # excluded from line_length_linter: \"R/no-line-length.R\" = list( line_length_linter = Inf ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-directories-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding directories completely","title":"Using lintr","text":"Entire directories also recognized supplied strings exclusions key. example, exclude renv folder linting R project using renv, set particularly useful projects include external code subdirectories.","code":"exclusions: list( \"renv\" )"},{"path":"https://lintr.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Jim Hester. Author, maintainer. Florent Angly. Author. fangly Russ Hyde. Author. Michael Chirico. Author. Kun Ren. Author. Alexander Rosenstock. Author. AshesITR Indrajeet Patil. Author. @patilindrajeets","code":""},{"path":"https://lintr.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hester J, Angly F, Hyde R, Chirico M, Ren K, Rosenstock , Patil (2023). lintr: 'Linter' R Code. https://github.com/r-lib/lintr, https://lintr.r-lib.org.","code":"@Manual{, title = {lintr: A 'Linter' for R Code}, author = {Jim Hester and Florent Angly and Russ Hyde and Michael Chirico and Kun Ren and Alexander Rosenstock and Indrajeet Patil}, year = {2023}, note = {https://github.com/r-lib/lintr, https://lintr.r-lib.org}, }"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"lintr","dir":"","previous_headings":"","what":"A Linter for R Code","title":"A Linter for R Code","text":"lintr provides static code analysis R. checks adherence given style, identifying syntax errors possible semantic issues, reports can take action. Watch lintr action following animation: lintr complementary {styler} package automatically restyles code, eliminating problems lintr can detect.","code":""},{"path":"https://lintr.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"A Linter for R Code","text":"Install stable version CRAN: development version GitHub:","code":"install.packages(\"lintr\") # install.packages(\"remotes\") remotes::install_github(\"r-lib/lintr\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"A Linter for R Code","text":"can create configuration file run selected linters: see list linters included configuration:","code":"lintr::use_lintr(type = \"tidyverse\") # in a project: lintr::lint_dir() # in a package: lintr::lint_package() # tidyverse (default) names(lintr::linters_with_defaults()) # full names(lintr::all_linters())"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"setting-up-github-actions","dir":"","previous_headings":"Usage","what":"Setting up GitHub Actions","title":"A Linter for R Code","text":"usethis provides helper functions generate lint workflows GitHub Actions: can also run lintr continuous integration within IDE text editor. See vignette(\"continuous-integration\") vignette(\"editors\") details. Without configuration, run default linters. See vignette(\"lintr\") learn modify defaults.","code":"# in a project: usethis::use_github_action(\"lint-project\") # in a package: usethis::use_github_action(\"lint\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"A Linter for R Code","text":"Please note lintr project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter closure — Linter","title":"Create a linter closure — Linter","text":"Create linter closure","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter closure — Linter","text":"","code":"Linter(fun, name = linter_auto_name())"},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter closure — Linter","text":"fun function takes source file returns lint objects. name Default name Linter. Lints produced linter labelled name default.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a linter closure — Linter","text":"function class set 'linter'.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"T and F symbol linter — T_and_F_symbol_linter","title":"T and F symbol linter — T_and_F_symbol_linter","text":"Avoid symbols T F, use TRUE FALSE instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"T_and_F_symbol_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"T and F symbol linter — T_and_F_symbol_linter","text":"best_practices, consistency, default, readability, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"# will produce lints lint( text = \"x <- T; y <- F\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[T_and_F_symbol_linter] Use TRUE instead of the symbol T. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[T_and_F_symbol_linter] Use FALSE instead of the symbol F. lint( text = \"T = 1.2; F = 2.4\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[T_and_F_symbol_linter] Don't use T as a variable name, as it can break code relying on T being TRUE. #> ::warning file=,line=1,col=11::file=,line=1,col=11,[T_and_F_symbol_linter] Don't use F as a variable name, as it can break code relying on F being FALSE. # okay lint( text = \"x <- c(TRUE, FALSE)\", linters = T_and_F_symbol_linter() ) lint( text = \"t = 1.2; f = 2.4\", linters = T_and_F_symbol_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Absolute path linter — absolute_path_linter","title":"Absolute path linter — absolute_path_linter","text":"Check absolute paths used (e.g. \"/var\", \"C:\\System\", \"~/docs\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Absolute path linter — absolute_path_linter","text":"","code":"absolute_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Absolute path linter — absolute_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Absolute path linter — absolute_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Absolute path linter — absolute_path_linter","text":"","code":"# Following examples use raw character constant syntax introduced in R 4.0. # will produce lints lint( text = 'R\"--[/blah/file.txt]--\"', linters = absolute_path_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[absolute_path_linter] Do not use absolute paths. # okay lint( text = 'R\"(./blah)\"', linters = absolute_path_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on all available linters — all_linters","title":"Create a linter configuration based on all available linters — all_linters","text":"Create linter configuration based available linters","code":""},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"all_linters(packages = \"lintr\", ...)"},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on all available linters — all_linters","text":"packages character vector packages search linters. ... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"names(all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"condition_message_linter\" \"conjunct_test_linter\" #> [13] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [15] \"duplicate_argument_linter\" \"empty_assignment_linter\" #> [17] \"equals_na_linter\" \"expect_comparison_linter\" #> [19] \"expect_identical_linter\" \"expect_length_linter\" #> [21] \"expect_named_linter\" \"expect_not_linter\" #> [23] \"expect_null_linter\" \"expect_s3_class_linter\" #> [25] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [27] \"expect_type_linter\" \"extraction_operator_linter\" #> [29] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [31] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [33] \"function_return_linter\" \"ifelse_censor_linter\" #> [35] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [37] \"indentation_linter\" \"infix_spaces_linter\" #> [39] \"inner_combine_linter\" \"is_numeric_linter\" #> [41] \"lengths_linter\" \"line_length_linter\" #> [43] \"literal_coercion_linter\" \"matrix_apply_linter\" #> [45] \"missing_argument_linter\" \"missing_package_linter\" #> [47] \"namespace_linter\" \"nested_ifelse_linter\" #> [49] \"nonportable_path_linter\" \"numeric_leading_zero_linter\" #> [51] \"object_length_linter\" \"object_name_linter\" #> [53] \"object_usage_linter\" \"outer_negation_linter\" #> [55] \"package_hooks_linter\" \"paren_body_linter\" #> [57] \"paste_linter\" \"pipe_call_linter\" #> [59] \"pipe_continuation_linter\" \"quotes_linter\" #> [61] \"redundant_equals_linter\" \"redundant_ifelse_linter\" #> [63] \"regex_subset_linter\" \"routine_registration_linter\" #> [65] \"semicolon_linter\" \"seq_linter\" #> [67] \"sort_linter\" \"spaces_inside_linter\" #> [69] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [71] \"string_boundary_linter\" \"strings_as_factors_linter\" #> [73] \"system_file_linter\" \"T_and_F_symbol_linter\" #> [75] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [77] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [79] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [81] \"unnecessary_lambda_linter\" \"unnecessary_nested_if_linter\" #> [83] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [85] \"unused_import_linter\" \"vector_logic_linter\" #> [87] \"whitespace_linter\" \"yoda_test_linter\""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"anyDuplicated() exists replacement (duplicated(.)), efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"any_duplicated_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"Also match usage like length(unique(x$col)) == nrow(x), can replaced anyDuplicated(x$col) == 0L.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"# will produce lints lint( text = \"any(duplicated(x), na.rm = TRUE)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). lint( text = \"length(unique(x)) == length(x)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). # okay lint( text = \"anyDuplicated(x)\", linters = any_duplicated_linter() ) lint( text = \"anyDuplicated(x) == 0L\", linters = any_duplicated_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"anyNA() exists replacement (.na(x)) efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"any_is_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"# will produce lints lint( text = \"any(is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). lint( text = \"any(is.na(foo(x)))\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). # okay lint( text = \"anyNA(x)\", linters = any_is_na_linter() ) lint( text = \"anyNA(foo(x))\", linters = any_is_na_linter() ) lint( text = \"any(!is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Assignment linter — assignment_linter","title":"Assignment linter — assignment_linter","text":"Check <- always used assignment.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assignment linter — assignment_linter","text":"","code":"assignment_linter( allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE )"},{"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.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Assignment linter — assignment_linter","text":"configurable, consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Assignment linter — assignment_linter","text":"","code":"# will produce lints lint( text = \"x = mean(x)\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not ->, for assignment. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[assignment_linter] ->> can have hard-to-predict behavior; prefer assigning to a specific environment instead (with assign() or <-). # okay lint( text = \"x <- mean(x)\", linters = assignment_linter() ) code_lines <- \"x <- 1\\ny <<- 2\" writeLines(code_lines) #> x <- 1 #> y <<- 2 lint( text = code_lines, linters = assignment_linter() ) # customizing using arguments code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter(allow_right_assign = TRUE) ) lint( text = \"x <<- 1\", linters = assignment_linter(allow_cascading_assign = FALSE) ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] <<- can have hard-to-predict behavior; prefer assigning to a specific environment instead (with assign() or <-). writeLines(\"foo(bar = \\n 1)\") #> foo(bar = #> 1) lint( text = \"foo(bar = \\n 1)\", linters = assignment_linter(allow_trailing = FALSE) ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[assignment_linter] Assignment = should not be trailing at end of line"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Linter metadata from a package — available_linters","title":"Get Linter metadata from a package — available_linters","text":"available_linters() obtains tagged list Linters available package. available_tags() searches available tags.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Linter metadata from a package — available_linters","text":"","code":"available_linters(packages = \"lintr\", tags = NULL, exclude_tags = \"deprecated\") available_tags(packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Linter metadata from a package — available_linters","text":"packages character vector packages search linters. tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. exclude_tags Tags exclude results. Linters least one matching tag returned. except_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get Linter metadata from a package — available_linters","text":"available_linters returns data frame columns 'linter', 'package' 'tags': linter character column naming function associated linter. package character column containing name package providing linter. tags list column containing tags associated linter. available_tags returns character vector linter tags used packages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"package-authors","dir":"Reference","previous_headings":"","what":"Package Authors","title":"Get Linter metadata from a package — available_linters","text":"implement available_linters() package, include file inst/lintr/linters.csv package. CSV file must contain columns 'linter' 'tags', UTF-8 encoded. Additional columns silently ignored present columns identified name. row describes linter function name (e.g. \"assignment_linter\") column 'linter'. space-separated tags associated linter (e.g. \"style consistency default\") column 'tags'. Tags snake_case. See available_tags(\"lintr\") find tags already used lintr.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get Linter metadata from a package — available_linters","text":"","code":"lintr_linters <- available_linters() # If the package doesn't exist or isn't installed, an empty data frame will be returned available_linters(\"does-not-exist\") #> [1] linter package tags #> <0 rows> (or 0-length row.names) lintr_linters2 <- available_linters(c(\"lintr\", \"does-not-exist\")) identical(lintr_linters, lintr_linters2) #> [1] TRUE available_tags() #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"readability\" \"robustness\" #> [13] \"style\""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Backport linter — backport_linter","title":"Backport linter — backport_linter","text":"Check usage unavailable functions. reliable testing r-devel dependencies.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Backport linter — backport_linter","text":"","code":"backport_linter(r_version = getRversion(), except = character())"},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Backport linter — backport_linter","text":"r_version Minimum R version test compatibility except Character vector functions excluded linting. Use list explicitly defined backports, e.g. imported backports package manually defined package.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Backport linter — backport_linter","text":"configurable, package_development, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Backport linter — backport_linter","text":"","code":"# will produce lints lint( text = \"trimws(x)\", linters = backport_linter(\"3.0.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] trimws (R 3.2.0) is not available for dependency R >= 3.0.0. Use the `except` argument of `backport_linter()` to configure available backports. lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] str2lang (R 3.6.0) is not available for dependency R >= 3.2.0. Use the `except` argument of `backport_linter()` to configure available backports. # okay lint( text = \"trimws(x)\", linters = backport_linter(\"3.6.0\") ) lint( text = \"str2lang(x)\", linters = backport_linter(\"4.0.0\") )"},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Best practices linters — best_practices_linters","title":"Best practices linters — best_practices_linters","text":"Linters checking use coding best practices, explicit typing numeric constants.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Best practices linters — best_practices_linters","text":"following linters tagged 'best_practices': absolute_path_linter any_duplicated_linter any_is_na_linter boolean_arithmetic_linter class_equals_linter commented_code_linter condition_message_linter conjunct_test_linter cyclocomp_linter empty_assignment_linter expect_comparison_linter expect_length_linter expect_named_linter expect_not_linter expect_null_linter expect_s3_class_linter expect_s4_class_linter expect_true_false_linter expect_type_linter extraction_operator_linter fixed_regex_linter for_loop_index_linter function_argument_linter function_return_linter ifelse_censor_linter implicit_assignment_linter implicit_integer_linter is_numeric_linter lengths_linter literal_coercion_linter nonportable_path_linter outer_negation_linter paste_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter seq_linter sort_linter system_file_linter T_and_F_symbol_linter undesirable_function_linter undesirable_operator_linter unnecessary_lambda_linter unnecessary_nested_if_linter unnecessary_placeholder_linter unreachable_code_linter unused_import_linter vector_logic_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"length((x == y)) == 0 !(x == y), latter readable efficient.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"boolean_arithmetic_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"# will produce lints lint( text = \"length(which(x == y)) == 0L\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). lint( text = \"sum(grepl(pattern, x)) == 0\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). # okay lint( text = \"!any(x == y)\", linters = boolean_arithmetic_linter() ) lint( text = \"!any(grepl(pattern, x))\", linters = boolean_arithmetic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Brace linter — brace_linter","title":"Brace linter — brace_linter","text":"Perform various style checks related placement spacing curly braces:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Brace linter — brace_linter","text":"","code":"brace_linter(allow_single_line = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Brace linter — brace_linter","text":"allow_single_line TRUE, allow open closed curly pair line.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Brace linter — brace_linter","text":"Opening curly braces never line always followed newline. Opening curly braces space . Closing curly braces line unless followed else. Closing curly braces conditions line corresponding else. Either neither branch /else use curly braces, .e., either branches use {...} neither . Functions spanning multiple lines use curly braces.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Brace linter — brace_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Brace linter — brace_linter","text":"","code":"# will produce lints lint( text = \"f <- function() { 1 }\", linters = brace_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line. #> ::warning file=,line=1,col=21::file=,line=1,col=21,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. writeLines(\"if (TRUE) {\\n return(1) }\") #> if (TRUE) { #> return(1) } lint( text = \"if (TRUE) {\\n return(1) }\", linters = brace_linter() ) #> ::warning file=,line=2,col=12::file=,line=2,col=12,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. # okay writeLines(\"f <- function() {\\n 1\\n}\") #> f <- function() { #> 1 #> } lint( text = \"f <- function() {\\n 1\\n}\", linters = brace_linter() ) writeLines(\"if (TRUE) { \\n return(1) \\n}\") #> if (TRUE) { #> return(1) #> } lint( text = \"if (TRUE) { \\n return(1) \\n}\", linters = brace_linter() ) # customizing using arguments writeLines(\"if (TRUE) { return(1) }\") #> if (TRUE) { return(1) } lint( text = \"if (TRUE) { return(1) }\", linters = brace_linter(allow_single_line = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Checkstyle Report for lint results — checkstyle_output","title":"Checkstyle Report for lint results — checkstyle_output","text":"Generate report linting results using Checkstyle XML format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Checkstyle Report for lint results — checkstyle_output","text":"","code":"checkstyle_output(lints, filename = \"lintr_results.xml\")"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Checkstyle Report for lint results — checkstyle_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block comparison of class with == — class_equals_linter","title":"Block comparison of class with == — class_equals_linter","text":"Usage like class(x) == \"character\" prone error since class R general vector. correct version S3 classes inherits(): inherits(x, \"character\"). Often, class k . equivalent, example .character() .data.frame().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block comparison of class with == — class_equals_linter","text":"","code":"class_equals_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block comparison of class with == — class_equals_linter","text":"Similar reasoning applies class(x) %% \"character\".","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block comparison of class with == — class_equals_linter","text":"best_practices, consistency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block comparison of class with == — class_equals_linter","text":"","code":"# will produce lints lint( text = 'is_lm <- class(x) == \"lm\"', linters = class_equals_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[class_equals_linter] Instead of comparing class(x) with ==, use inherits(x, 'class-name') or is. or is(x, 'class') lint( text = 'if (\"lm\" %in% class(x)) is_lm <- TRUE', linters = class_equals_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[class_equals_linter] Instead of comparing class(x) with %in%, use inherits(x, 'class-name') or is. or is(x, 'class') # okay lint( text = 'is_lm <- inherits(x, \"lm\")', linters = class_equals_linter() ) lint( text = 'if (inherits(x, \"lm\")) is_lm <- TRUE', linters = class_equals_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":null,"dir":"Reference","previous_headings":"","what":"Clear the lintr cache — clear_cache","title":"Clear the lintr cache — clear_cache","text":"Clear lintr cache","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Clear the lintr cache — clear_cache","text":"","code":"clear_cache(file = NULL, path = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Clear the lintr cache — clear_cache","text":"file filename whose cache clear. pass NULL, delete caches. path directory store caches. Reads option 'lintr.cache_directory' default.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Clear the lintr cache — clear_cache","text":"0 success, 1 failure, invisibly.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commas linter — commas_linter","title":"Commas linter — commas_linter","text":"Check commas followed spaces, spaces .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commas linter — commas_linter","text":"","code":"commas_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commas linter — commas_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commas linter — commas_linter","text":"","code":"# will produce lints lint( text = \"switch(op , x = foo, y = bar)\", linters = commas_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[commas_linter] Commas should never have a space before. lint( text = \"mean(x,trim = 0.2,na.rm = TRUE)\", linters = commas_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[commas_linter] Commas should always have a space after. #> ::warning file=,line=1,col=19::file=,line=1,col=19,[commas_linter] Commas should always have a space after. lint( text = \"x[ ,, drop=TRUE]\", linters = commas_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commas_linter] Commas should never have a space before. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Commas should always have a space after. # okay lint( text = \"switch(op, x = foo, y = bar)\", linters = commas_linter() ) lint( text = \"switch(op, x = , y = bar)\", linters = commas_linter() ) lint( text = \"mean(x, trim = 0.2, na.rm = TRUE)\", linters = commas_linter() ) lint( text = \"a[1, , 2, , 3]\", linters = commas_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commented code linter — commented_code_linter","title":"Commented code linter — commented_code_linter","text":"Check commented code outside roxygen blocks.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commented code linter — commented_code_linter","text":"","code":"commented_code_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commented code linter — commented_code_linter","text":"best_practices, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commented code linter — commented_code_linter","text":"","code":"# will produce lints lint( text = \"# x <- 1\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Commented code should be removed. lint( text = \"x <- f() # g()\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[commented_code_linter] Commented code should be removed. lint( text = \"x + y # + z[1, 2]\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[commented_code_linter] Commented code should be removed. # okay lint( text = \"x <- 1; x <- f(); x + y\", linters = commented_code_linter() ) lint( text = \"#' x <- 1\", linters = commented_code_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Common mistake linters — common_mistakes_linters","title":"Common mistake linters — common_mistakes_linters","text":"Linters highlighting common mistakes, duplicate arguments.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Common mistake linters — common_mistakes_linters","text":"following linters tagged 'common_mistakes': duplicate_argument_linter equals_na_linter missing_argument_linter missing_package_linter redundant_equals_linter sprintf_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"linter discourages combining condition functions like stop() string concatenation functions paste() paste0(). ","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"condition_message_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"stop(paste0(...)) redundant exactly equivalent stop(...) stop(paste(...)) similarly equivalent stop(...) separators (see examples) applies default condition functions well, .e., warning(), message(), packageStartupMessage().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"best_practices, consistency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"# will produce lints lint( text = 'stop(paste(\"a string\", \"another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste to build stop strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). lint( text = 'warning(paste0(\"a string\", \" another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste0 to build warning strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). # okay lint( text = 'stop(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(paste(\"a string\", \"another\", sep = \"-\"))', linters = condition_message_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Configurable linters — configurable_linters","title":"Configurable linters — configurable_linters","text":"Generic linters support custom configuration needs.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Configurable linters — configurable_linters","text":"following linters tagged 'configurable': absolute_path_linter assignment_linter backport_linter brace_linter conjunct_test_linter cyclocomp_linter duplicate_argument_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter line_length_linter missing_argument_linter namespace_linter nonportable_path_linter object_length_linter object_name_linter object_usage_linter paste_linter quotes_linter redundant_ifelse_linter semicolon_linter string_boundary_linter todo_comment_linter trailing_whitespace_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"readability test outputs, testing one thing per call testthat::expect_true() preferable, .e., expect_true(); expect_true(B) better expect_true(&& B), expect_false(); expect_false(B) better expect_false(|| B).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"","code":"conjunct_test_linter(allow_named_stopifnot = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"allow_named_stopifnot Logical, TRUE default. FALSE, \"named\" calls stopifnot(), available since R 4.0.0 provide helpful messages test failures, also linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"Similar reasoning applies && usage inside stopifnot() assertthat::assert_that() calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"best_practices, configurable, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force && conditions in expect_true() and expect_false() to be written separately — conjunct_test_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x && y)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of expect_true(A && B), write multiple expectations like expect_true(A) and expect_true(B) The latter will produce better error messages in the case of failure. lint( text = \"expect_false(x || (y && z))\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of expect_false(A || B), write multiple expectations like expect_false(A) and expect_false(B) The latter will produce better error messages in the case of failure. lint( text = \"stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))\", linters = conjunct_test_linter(allow_named_stopifnot = FALSE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Instead of stopifnot(A && B), write multiple conditions like stopifnot(A, B). The latter will produce better error messages in the case of failure. # okay lint( text = \"expect_true(x || (y && z))\", linters = conjunct_test_linter() ) lint( text = 'stopifnot(\"x must be a logical scalar\" = length(x) == 1 && is.logical(x) && !is.na(x))', linters = conjunct_test_linter(allow_named_stopifnot = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"stopifnot() accepts number tests, sequences like stopifnot(x); stopifnot(y) redundant. Ditto tests using assertthat::assert_that() without specifying msg=.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"consecutive_assertion_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"# will produce lints lint( text = \"stopifnot(x); stopifnot(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to stopifnot(). lint( text = \"assert_that(x); assert_that(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to assert_that(). # okay lint( text = \"stopifnot(x, y)\", linters = consecutive_assertion_linter() ) lint( text = 'assert_that(x, msg = \"Bad x!\"); assert_that(y)', linters = consecutive_assertion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Consistency linters — consistency_linters","title":"Consistency linters — consistency_linters","text":"Linters checking enforcing consistent alternative multiple syntactically valid ways write something.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Consistency linters — consistency_linters","text":"following linters tagged 'consistency': assignment_linter class_equals_linter condition_message_linter consecutive_assertion_linter function_argument_linter implicit_integer_linter inner_combine_linter is_numeric_linter literal_coercion_linter numeric_leading_zero_linter object_name_linter paste_linter quotes_linter redundant_ifelse_linter seq_linter system_file_linter T_and_F_symbol_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Correctness linters — correctness_linters","title":"Correctness linters — correctness_linters","text":"Linters highlighting possible programming mistakes, unused variables.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Correctness linters — correctness_linters","text":"following linters tagged 'correctness': duplicate_argument_linter equals_na_linter missing_argument_linter namespace_linter object_usage_linter package_hooks_linter sprintf_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Cyclomatic complexity linter — cyclocomp_linter","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"Check overly complicated expressions. See cyclocomp::cyclocomp().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"cyclocomp_linter(complexity_limit = 15L)"},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"complexity_limit Maximum cyclomatic complexity, default 15. Expressions complex linted. See cyclocomp::cyclocomp().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"best_practices, configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"# will produce lints lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 1L) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[cyclocomp_linter] Functions should have cyclomatic complexity of less than 1, this has 2. # okay lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 2L) )"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Default linters — default_linters","title":"Default linters — default_linters","text":"List default linters lint(). Use linters_with_defaults() customize . default linters based tidyverse style guide. set default linters follows (parameterized linters, e.g., line_length_linter use default argument(s), see ? details):","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default linters — default_linters","text":"","code":"default_linters"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default linters — default_linters","text":"object class list length 25.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Default linters — default_linters","text":"following linters tagged 'default': assignment_linter brace_linter commas_linter commented_code_linter cyclocomp_linter equals_na_linter function_left_parentheses_linter indentation_linter infix_spaces_linter line_length_linter object_length_linter object_name_linter object_usage_linter paren_body_linter pipe_continuation_linter quotes_linter semicolon_linter seq_linter spaces_inside_linter spaces_left_parentheses_linter T_and_F_symbol_linter trailing_blank_lines_linter trailing_whitespace_linter vector_logic_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":null,"dir":"Reference","previous_headings":"","what":"Default lintr settings — default_settings","title":"Default lintr settings — default_settings","text":"default settings consist linters: list default linters (see default_linters()) encoding: character encoding assumed file exclude: pattern used exclude line code exclude_start, exclude_end: patterns used mark start end code block exclude exclude_linter, exclude_linter_sep: patterns used exclude linters exclusions:list files exclude cache_directory: location cache directory comment_token: GitHub token character comment_bot: decides lintr comment bot GitHub can comment commits error_on_lint: decides error produced lints found","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default lintr settings — default_settings","text":"","code":"default_settings"},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default lintr settings — default_settings","text":"object class list length 12.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Default lintr settings — default_settings","text":"","code":"# available settings names(default_settings) #> [1] \"linters\" \"encoding\" \"exclude\" #> [4] \"exclude_start\" \"exclude_end\" \"exclude_linter\" #> [7] \"exclude_linter_sep\" \"exclusions\" \"cache_directory\" #> [10] \"comment_token\" \"comment_bot\" \"error_on_lint\" # linters included by default names(default_settings$linters) #> [1] \"assignment_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"cyclocomp_linter\" \"equals_na_linter\" #> [7] \"function_left_parentheses_linter\" \"indentation_linter\" #> [9] \"infix_spaces_linter\" \"line_length_linter\" #> [11] \"object_length_linter\" \"object_name_linter\" #> [13] \"object_usage_linter\" \"paren_body_linter\" #> [15] \"pipe_continuation_linter\" \"quotes_linter\" #> [17] \"semicolon_linter\" \"seq_linter\" #> [19] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [21] \"T_and_F_symbol_linter\" \"trailing_blank_lines_linter\" #> [23] \"trailing_whitespace_linter\" \"vector_logic_linter\" #> [25] \"whitespace_linter\" # default values for a few of the other settings default_settings[c( \"encoding\", \"exclude\", \"exclude_start\", \"exclude_end\", \"exclude_linter\", \"exclude_linter_sep\", \"exclusions\", \"error_on_lint\" )] #> $encoding #> [1] \"UTF-8\" #> #> $exclude #> #[[:space:]]*nolint #> #> $exclude_start #> #[[:space:]]*nolint start #> #> $exclude_end #> #[[:space:]]*nolint end #> #> $exclude_linter #> ^[[:space:]]*:[[:space:]]*(?(?:(?:[^,.])+[[:space:]]*,[[:space:]]*)*(?:[^,.])+)\\. #> #> $exclude_linter_sep #> [[:space:]]*,[[:space:]]* #> #> $exclusions #> list() #> #> $error_on_lint #> [1] FALSE #>"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":null,"dir":"Reference","previous_headings":"","what":"Default undesirable functions and operators — all_undesirable_functions","title":"Default undesirable functions and operators — all_undesirable_functions","text":"Lists function names operators undesirable_function_linter() undesirable_operator_linter(). list default elements another contains available elements. Use modify_defaults() produce custom list.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default undesirable functions and operators — all_undesirable_functions","text":"","code":"all_undesirable_functions default_undesirable_functions all_undesirable_operators default_undesirable_operators"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default undesirable functions and operators — all_undesirable_functions","text":"named list character strings.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Default undesirable functions and operators — all_undesirable_functions","text":"following functions sometimes regarded undesirable: attach() modifies global search path. Use roxygen2's @importFrom statement packages, :: scripts. browser() pauses execution run likely leftover debugging. removed. debug() traps function causes execution pause function run. removed. debugcall() works similarly debug(), causing execution pause. removed. debugonce() useful interactive debugging. removed. detach() modifies global search path. Detaching environments search path rarely necessary production code. ifelse() type stable. Use /else block scalar logic, use dplyr::if_else()/data.table::fifelse() type stable vectorized logic. .libPaths() permanently modifies library location. Use withr::with_libpaths() temporary change instead. library() modifies global search path. Use roxygen2's @importFrom statement packages, :: scripts. loadNamespace() provide easy way signal failures. Use return value requireNamespace() instead. mapply() type stable. Use Map() guarantee list returned simplify accordingly. options() permanently modifies session options. Use withr::with_options() temporary change instead. par() permanently modifies graphics device parameters. Use withr::with_par() temporary change instead. require() modifies global search path. Use roxygen2's @importFrom statement packages, library() :: scripts. sapply() type stable. Use vapply() appropriate FUN.VALUE= argument obtain type stable simplification. setwd() modifies global working directory. Use withr::with_dir() temporary change instead. sink() permanently redirects output. Use withr::with_sink() temporary redirection instead. source() loads code global environment unless local = TRUE used, can cause unexpected behavior. substring() replaced substr() appropriate stop= value. Sys.setenv() permanently modifies global environment variables. Use withr::with_envvar() temporary change instead. Sys.setlocale() permanently modifies session locale. Use withr::with_locale() temporary change instead. trace() traps function causes execution arbitrary code function run. removed. undebug() useful interactive debugging debug(). removed. untrace() useful interactive debugging trace(). removed. following operators sometimes regarded undesirable: ::: accesses non-exported functions inside packages. Code relying likely break future versions package functions part public interface may changed removed maintainers without notice. Use public functions via :: instead. <<- ->> assign outside current environment way can hard reason . Prefer fully-encapsulated functions wherever possible, , necessary, assign specific environment assign(). Recall can create environment desired scope new.env().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated linters — deprecated_linters","title":"Deprecated linters — deprecated_linters","text":"Linters deprecated provided backwards compatibility . linters excluded linters_with_tags() default.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Deprecated linters — deprecated_linters","text":"following linters tagged 'deprecated': closed_curly_linter consecutive_stopifnot_linter no_tab_linter open_curly_linter paren_brace_linter semicolon_terminator_linter single_quotes_linter unneeded_concatenation_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Duplicate argument linter — duplicate_argument_linter","title":"Duplicate argument linter — duplicate_argument_linter","text":"Check duplicate arguments function calls. cases run-time errors (e.g. mean(x = 1:5, x = 2:3)), otherwise linter used discourage explicitly providing duplicate names objects (e.g. c(= 1, = 2)). Duplicate-named objects hard work programmatically typically avoided.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"duplicate_argument_linter(except = c(\"mutate\", \"transmute\"))"},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Duplicate argument linter — duplicate_argument_linter","text":"except character vector function names exceptions. Defaults functions allow sequential updates variables, currently dplyr::mutate() dplyr::transmute().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Duplicate argument linter — duplicate_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"# will produce lints lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[duplicate_argument_linter] Duplicate arguments in function call. lint( text = \"fun(arg = 1, arg = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[duplicate_argument_linter] Duplicate arguments in function call. # okay lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter(except = \"list\") ) lint( text = \"df %>% dplyr::mutate(x = a + b, x = x + d)\", linters = duplicate_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Efficiency linters — efficiency_linters","title":"Efficiency linters — efficiency_linters","text":"Linters highlighting code efficiency problems, unnecessary function calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Efficiency linters — efficiency_linters","text":"following linters tagged 'efficiency': any_duplicated_linter any_is_na_linter boolean_arithmetic_linter fixed_regex_linter ifelse_censor_linter inner_combine_linter lengths_linter literal_coercion_linter matrix_apply_linter nested_ifelse_linter outer_negation_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter seq_linter sort_linter string_boundary_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unnecessary_lambda_linter vector_logic_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block assignment of {} — empty_assignment_linter","title":"Block assignment of {} — empty_assignment_linter","text":"Assignment {} assignment NULL; use latter clarity. Closely related: unnecessary_concatenation_linter().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"empty_assignment_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block assignment of {} — empty_assignment_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"# will produce lints lint( text = \"x <- {}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. writeLines(\"x = {\\n}\") #> x = { #> } lint( text = \"x = {\\n}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. # okay lint( text = \"x <- { 3 + 4 }\", linters = empty_assignment_linter() ) lint( text = \"x <- NULL\", linters = empty_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality check with NA linter — equals_na_linter","title":"Equality check with NA linter — equals_na_linter","text":"Check x == NA x != NA. usage almost surely incorrect -- checks missing values done .na().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality check with NA linter — equals_na_linter","text":"","code":"equals_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Equality check with NA linter — equals_na_linter","text":"common_mistakes, correctness, default, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality check with NA linter — equals_na_linter","text":"","code":"# will produce lints lint( text = \"x == NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or !=) lint( text = \"x != NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or !=) # okay lint( text = \"is.na(x)\", linters = equals_na_linter() ) lint( text = \"!is.na(x)\", linters = equals_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":null,"dir":"Reference","previous_headings":"","what":"Exclude lines or files from linting — exclude","title":"Exclude lines or files from linting — exclude","text":"Exclude lines files linting","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Exclude lines or files from linting — exclude","text":"","code":"exclude(lints, exclusions = settings$exclusions, linter_names = NULL, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Exclude lines or files from linting — exclude","text":"lints need filtered. exclusions manually specified exclusions linter_names character vector names active linters, used parsing inline exclusions. ... additional arguments passed parse_exclusions()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Exclude lines or files from linting — exclude","text":"Exclusions can specified three different ways. single line source file. default: # nolint, possibly followed listing linters exclude. listing missing, linters excluded line. default listing format # nolint: linter_name, linter2_name.. may anything colon line exclusion tag listing must terminated full stop (.) linter list respected. line range source file. default: # nolint start, # nolint end. # nolint start accepts linter lists form # nolint. exclusions parameter, named list files named lists linters lines exclude , named list files lines exclude, just filenames want exclude entire file, directory names want exclude files directory.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Code executing linters — executing_linters","title":"Code executing linters — executing_linters","text":"Linters evaluate parts linted code, loading referenced packages. linters used untrusted code, may need dependencies linted package project available order function correctly.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Code executing linters — executing_linters","text":"following linters tagged 'executing': namespace_linter object_length_linter object_name_linter object_usage_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"testthat::expect_gt(), testthat::expect_gte(), testthat::expect_lt(), testthat::expect_lte(), testthat::expect_equal() exist specifically testing comparisons two objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"expect_comparison_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x > y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y). lint( text = \"expect_true(x <= y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y). lint( text = \"expect_true(x == (y == 2))\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y). # okay lint( text = \"expect_gt(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_lte(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_identical(x, y == 2)\", linters = expect_comparison_linter() ) lint( text = \"expect_true(x < y | x > y^2)\", linters = expect_comparison_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter enforces usage testthat::expect_identical() default expectation comparisons testthat suite. expect_true(identical(x, y)) equivalent unadvised method test. , testthat::expect_equal() used expect_identical() inappropriate, .e., x y need numerically equivalent instead fully identical (case, provide tolerance= argument expect_equal() explicitly). also applies inconvenient check full equality (e.g., names can ignored, case ignore_attr = \"names\" supplied expect_equal() (, 2nd edition, check.attributes = FALSE).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"expect_identical_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter allows expect_equal() three circumstances: named argument set (e.g. ignore_attr tolerance) Comparison made explicit decimal, e.g. expect_equal(x, 1.0) (implicitly setting tolerance) ... passed (wrapper functions might set arguments ignore_attr tolerance)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, y)\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. lint( text = \"expect_true(identical(x, y))\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. # okay lint( text = \"expect_identical(x, y)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, check.attributes = FALSE)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, tolerance = 1e-6)\", linters = expect_identical_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"testthat::expect_length() exists specifically testing length() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"expect_length_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(length(x), 2L)\", linters = expect_length_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n) # okay lint( text = \"expect_length(x, 2L)\", linters = expect_length_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint expectation — expect_lint","title":"Lint expectation — expect_lint","text":"expectation function test lints produced lint satisfy number checks.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint expectation — expect_lint","text":"","code":"expect_lint(content, checks, ..., file = NULL, language = \"en\")"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lint expectation — expect_lint","text":"content character vector file content linted, vector element representing line text. checks checks performed: NULL check lints returned. single string regex object check single lint returned matching message. named list check single lint returned fields match. Accepted fields taken Lint(). list named lists multiple lints returned, check matches checks corresponding named list (described point ). Named vectors also accepted instead named lists, compatibility feature recommended new code. ... arguments passed lint(), e.g. linters cache use. file NULL, read content specified file rather content. language temporarily override Rs LANGUAGE envvar, controlling localization base R error messages. makes testing reproducible systems irrespective native R language setting.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lint expectation — expect_lint","text":"NULL, invisibly.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint expectation — expect_lint","text":"","code":"# no expected lint expect_lint(\"a\", NULL, trailing_blank_lines_linter()) # one expected lint expect_lint(\"a\\n\", \"superfluous\", trailing_blank_lines_linter()) expect_lint(\"a\\n\", list(message = \"superfluous\", line_number = 2), trailing_blank_lines_linter()) # several expected lints expect_lint(\"a\\n\\n\", list(\"superfluous\", \"superfluous\"), trailing_blank_lines_linter()) expect_lint( \"a\\n\\n\", list( list(message = \"superfluous\", line_number = 2), list(message = \"superfluous\", line_number = 3) ), trailing_blank_lines_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":null,"dir":"Reference","previous_headings":"","what":"Test that the package is lint free — expect_lint_free","title":"Test that the package is lint free — expect_lint_free","text":"function thin wrapper around lint_package simply tests lints package. can used ensure tests fail package contains lints.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test that the package is lint free — expect_lint_free","text":"","code":"expect_lint_free(...)"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test that the package is lint free — expect_lint_free","text":"... arguments passed lint_package()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"testthat::expect_named() exists specifically testing names() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"expect_named_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(names(x), \"a\")', linters = expect_named_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n) # okay lint( text = 'expect_named(x, \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(colnames(x), \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(dimnames(x), \"a\")', linters = expect_named_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"testthat::expect_false() exists specifically testing output FALSE. testthat::expect_true() can also used tests negating output, better use tailored function instead. reverse also true -- use expect_false() instead expect_true(!).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"expect_not_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"# will produce lints lint( text = \"expect_true(!x)\", linters = expect_not_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa. # okay lint( text = \"expect_false(x)\", linters = expect_not_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_null for checking NULL — expect_null_linter","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"Require usage expect_null(x) expect_equal(x, NULL) similar usages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"expect_null_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"testthat::expect_null() exists specifically testing NULL objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_equal(x, NULL) lint( text = \"expect_identical(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_identical(x, NULL) lint( text = \"expect_true(is.null(x))\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_true(is.null(x)) # okay lint( text = \"expect_null(x)\", linters = expect_null_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s3_class() — expect_s3_class_linter","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"testthat::expect_s3_class() exists specifically testing class S3 objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"expect_s3_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(class(x), \"data.frame\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. lint( text = 'expect_equal(class(x), \"numeric\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. # okay lint( text = 'expect_s3_class(x, \"data.frame\")', linters = expect_s3_class_linter() ) lint( text = 'expect_type(x, \"double\")', linters = expect_s3_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"testthat::expect_s4_class() exists specifically testing class S4 objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"expect_s4_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"# will produce lints lint( text = 'expect_true(is(x, \"Matrix\"))', linters = expect_s4_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s4_class_linter] expect_s4_class(x, k) is better than expect_true(is(x, k)). Note also expect_s3_class() available for testing S3 objects. # okay lint( text = 'expect_s4_class(x, \"Matrix\")', linters = expect_s4_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"testthat::expect_true() testthat::expect_false() exist specifically testing TRUE/FALSE value object. testthat::expect_equal() testthat::expect_identical() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"expect_true_false_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"best_practices, package_development, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, TRUE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE) lint( text = \"expect_equal(x, FALSE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE) # okay lint( text = \"expect_true(x)\", linters = expect_true_false_linter() ) lint( text = \"expect_false(x)\", linters = expect_true_false_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"testthat::expect_type() exists specifically testing storage type objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"expect_type_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"best_practices, package_development","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t) lint( text = 'expect_identical(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t) # okay lint( text = 'expect_type(x, \"double\")', linters = expect_type_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Extraction operator linter — extraction_operator_linter","title":"Extraction operator linter — extraction_operator_linter","text":"Check [[ operator used extracting single element object, [ (subsetting) $ (interactive use).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extraction operator linter — extraction_operator_linter","text":"","code":"extraction_operator_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extraction operator linter — extraction_operator_linter","text":"three subsetting operators R ([[, [, $) interact differently different data structures (atomic vector, list, data frame, etc.). reasons prefer [[ operator [ $ want extract element data frame list: Subsetting list [ always returns smaller list, [[ returns list element. Subsetting named atomic vector [ returns named vector, [[ returns vector element. Subsetting data frame (tibble) [ type unstable; can return vector data frame. [[, hand, always returns vector. data frame (tibble), $ partial matching (e.g. df$subset df$abc), can source bugs. [[ partial matching. data frames (tibbles), irrespective size, [[ operator slower $. lists, however, reverse true.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Extraction operator linter — extraction_operator_linter","text":"Subsetting chapter Advanced R (Wickham, 2019).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Extraction operator linter — extraction_operator_linter","text":"best_practices, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/extraction_operator_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extraction operator linter — extraction_operator_linter","text":"","code":"# will produce lints lint( text = 'iris[\"Species\"]', linters = extraction_operator_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[extraction_operator_linter] Use `[[` instead of `[` to extract an element. lint( text = \"iris$Species\", linters = extraction_operator_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[extraction_operator_linter] Use `[[` instead of `$` to extract an element. # okay lint( text = 'iris[[\"Species\"]]', linters = extraction_operator_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"Invoking regular expression engine overkill cases search pattern involves static patterns.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"fixed_regex_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"NB: stringr functions, means wrapping pattern stringr::fixed(). NB: linter likely able distinguish every possible case fixed regular expression preferable, rather seeks identify likely cases. never report false positives, however; please report false positives error.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"# will produce lints code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x) lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \".\" with fixed = TRUE. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \"a*b\" with fixed = TRUE. code_lines <- 'stringr::str_subset(x, \"\\\\\\\\$\")' writeLines(code_lines) #> stringr::str_subset(x, \"\\\\$\") lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use stringr::fixed(\"$\") as the pattern. lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use \"Munich\" with fixed = TRUE. # okay code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x, fixed = TRUE)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x, fixed = TRUE) lint( text = code_lines, linters = fixed_regex_linter() ) lint( text = 'grepl(\"a*b\", x, fixed = TRUE)', linters = fixed_regex_linter() ) lint( text = 'stringr::str_subset(x, stringr::fixed(\"$\"))', linters = fixed_regex_linter() ) lint( text = 'grepl(\"Munich\", address, fixed = TRUE)', linters = fixed_regex_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"(x x) poor choice indexing variable. overwrites x calling scope confusing read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"for_loop_index_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"best_practices, readability, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"# will produce lints lint( text = \"for (x in x) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. lint( text = \"for (x in foo(x, y)) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. # okay lint( text = \"for (xi in x) { TRUE }\", linters = for_loop_index_linter() ) lint( text = \"for (col in DF$col) { TRUE }\", linters = for_loop_index_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function argument linter — function_argument_linter","title":"Function argument linter — function_argument_linter","text":"Check arguments defaults come last function declarations, per tidyverse design guide. Changing argument order can breaking change. alternative changing argument order instead set default arguments NULL.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function argument linter — function_argument_linter","text":"","code":"function_argument_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function argument linter — function_argument_linter","text":"best_practices, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function argument linter — function_argument_linter","text":"","code":"# will produce lints lint( text = \"function(y = 1, z = 2, x) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[function_argument_linter] Arguments without defaults should come before arguments with defaults. lint( text = \"function(x, y, z = 1, ..., w) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=28::file=,line=1,col=28,[function_argument_linter] Arguments without defaults should come before arguments with defaults. # okay lint( text = \"function(x, y = 1, z = 2) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, w, z = 1, ...) {}\", linters = function_argument_linter() ) lint( text = \"function(y = 1, z = 2, x = NULL) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, z = 1, ..., w = NULL) {}\", linters = function_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function left parentheses linter — function_left_parentheses_linter","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Check left parentheses function call spaces (e.g. mean (1:3)). Although syntactically valid, makes code difficult read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"function_left_parentheses_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Exceptions made control flow functions (, , etc.).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function left parentheses linter — function_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"mean (x)\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. lint( text = \"stats::sd(c (x, y, z))\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. # okay lint( text = \"mean(x)\", linters = function_left_parentheses_linter() ) lint( text = \"stats::sd(c(x, y, z))\", linters = function_left_parentheses_linter() ) lint( text = \"foo <- function(x) (x + 1)\", linters = function_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"return(x <- ...) either distracting (x ignored), confusing (assigning x side effect muddled dual-purpose expression).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"function_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"# will produce lints lint( text = \"foo <- function(x) return(y <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. lint( text = \"foo <- function(x) return(x <<- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. writeLines(\"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\") #> e <- new.env() #> foo <- function(x) return(e$val <- x + 1) lint( text = \"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=2,col=27::file=,line=2,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. # okay lint( text = \"foo <- function(x) return(x + 1)\", linters = function_return_linter() ) code_lines <- \" foo <- function(x) { x <<- x + 1 return(x) } \" lint( text = code_lines, linters = function_return_linter() ) code_lines <- \" e <- new.env() foo <- function(x) { e$val <- x + 1 return(e$val) } \" writeLines(code_lines) #> #> e <- new.env() #> foo <- function(x) { #> e$val <- x + 1 #> return(e$val) #> } #> lint( text = code_lines, linters = function_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract text from STR_CONST nodes — get_r_string","title":"Extract text from STR_CONST nodes — get_r_string","text":"Convert STR_CONST text() values R strings. useful account arbitrary character literals valid since R 4.0, e.g. R\"------[hello]------\", parsed R \"hello\". quite cumbersome write XPaths allowing strings like , whenever linter logic requires testing STR_CONST node's value, use function. NB: also properly vectorized s, accepts variety inputs. Empty inputs become NA outputs, helps ensure length(get_r_string(s)) == length(s).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract text from STR_CONST nodes — get_r_string","text":"","code":"get_r_string(s, xpath = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract text from STR_CONST nodes — get_r_string","text":"s input string strings. s xml_node xml_nodeset xpath NULL, extract string value xml2::xml_text(). s xml_node xml_nodeset xpath specified, extracted xml2::xml_find_chr(). xpath XPath, passed xml2::xml_find_chr() wrapping string().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract text from STR_CONST nodes — get_r_string","text":"","code":"tmp <- withr::local_tempfile(lines = \"c('a', 'b')\") expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content #> Warning: cannot open file '/tmp/RtmpSYI7YV/file16835ad243f2': No such file or directory #> Error in file(con, \"r\"): cannot open the connection writeLines(as.character(expr_as_xml)) #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found get_r_string(expr_as_xml, \"expr[2]\") # \"a\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found get_r_string(expr_as_xml, \"expr[3]\") # \"b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml' not found # more importantly, extract strings under R>=4 raw strings tmp4.0 <- withr::local_tempfile(lines = \"c(R'(a\\\\b)', R'--[a\\\\\\\"\\'\\\"\\\\b]--')\") expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content #> Warning: cannot open file '/tmp/RtmpSYI7YV/file16838231738': No such file or directory #> Error in file(con, \"r\"): cannot open the connection writeLines(as.character(expr_as_xml4.0)) #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found get_r_string(expr_as_xml4.0, \"expr[2]\") # \"a\\b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found get_r_string(expr_as_xml4.0, \"expr[3]\") # \"a\\\\\"'\\\"\\b\" #> Error in eval(expr, envir, enclos): object 'expr_as_xml4.0' not found"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":null,"dir":"Reference","previous_headings":"","what":"Parsed sourced file from a filename — get_source_expressions","title":"Parsed sourced file from a filename — get_source_expressions","text":"object given input linter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"get_source_expressions(filename, lines = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Parsed sourced file from a filename — get_source_expressions","text":"filename file parsed. lines character vector lines. NULL, filename read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Parsed sourced file from a filename — get_source_expressions","text":"list three components: expressions list n+1 objects. first n elements correspond expression filename, consist list 9 elements: filename (character) line (integer) line filename expression begins column (integer) column filename expression begins lines (named character) vector lines spanned expression, named line number corresponding filename parsed_content (data.frame) given utils::getParseData() expression xml_parsed_content (xml_document) XML parse tree expression given xmlparsedata::xml_parse_data() content (character) lines single string (split across lines) (Deprecated) find_line (function) function returning lines expression (Deprecated) find_column (function) similar function columns final element expressions list corresponding full file consisting 6 elements: filename (character) file_lines (character) readLines() output file content (character) .R files, file_lines; .Rmd .qmd scripts, extracted R source code (text) full_parsed_content (data.frame) given utils::getParseData() full content full_xml_parsed_content (xml_document) XML parse tree expressions given xmlparsedata::xml_parse_data() terminal_newline (logical) records whether filename terminal newline (determined readLines() producing corresponding warning) error Lint object describing parsing error. lines readLines() output file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Parsed sourced file from a filename — get_source_expressions","text":"file read using encoding setting. setting found taking first valid result following locations encoding key usual lintr configuration settings. Encoding field Package DESCRIPTION file parent directory. Encoding field R Project .Rproj file parent directory. \"UTF-8\" fallback.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) get_source_expressions(tmp) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683747826eb': No such file or directory #> Error in file(con, \"r\"): cannot open the connection"},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":null,"dir":"Reference","previous_headings":"","what":"Get parsed IDs by token — ids_with_token","title":"Get parsed IDs by token — ids_with_token","text":"Gets source IDs (row indices) corresponding given token.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get parsed IDs by token — ids_with_token","text":"","code":"ids_with_token(source_expression, value, fun = `==`, source_file = NULL) with_id(source_expression, id, source_file)"},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get parsed IDs by token — ids_with_token","text":"source_expression list source expressions, result call get_source_expressions(), desired filename. value Character. String corresponding token search . example: \"SYMBOL\" \"FUNCTION\" \"EQ_FORMALS\" \"$\" \"(\" fun additional flexibility, function search token column parsed_content. Typically == %%. source_file (DEPRECATED) source_expression. removed. id Integer. index corresponding desired row parsed_content.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get parsed IDs by token — ids_with_token","text":"ids_with_token: indices parsed_content data frame entry list source expressions. Indices correspond rows fun evaluates TRUE value token column. with_id: data frame corresponding row(s) specified id.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Get parsed IDs by token — ids_with_token","text":"with_id(): Return row parsed_content entry [get_source_expressions]() object. Typically used conjunction ids_with_token iterate rows containing desired tokens.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ids_with_token.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get parsed IDs by token — ids_with_token","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) source_exprs <- get_source_expressions(tmp) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683130a6da9': No such file or directory #> Error in file(con, \"r\"): cannot open the connection ids_with_token(source_exprs$expressions[[1L]], value = \"SYMBOL\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found with_id(source_exprs$expressions[[1L]], 2L) #> Error in eval(expr, envir, enclos): object 'source_exprs' not found"},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"ifelse(x > M, M, x) pmin(x, M), harder read requires several passes vector.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"","code":"ifelse_censor_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"goes similar ways censor vector, e.g. ifelse(x <= M, x, M) pmin(x, M), ifelse(x < m, m, x) pmax(x, m), ifelse(x >= m, x, m) pmax(x, m).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/ifelse_censor_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of ifelse() where pmin() or pmax() is more appropriate — ifelse_censor_linter","text":"","code":"# will produce lints lint( text = \"ifelse(5:1 < pi, 5:1, pi)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmin(x, y) is preferable to ifelse(x < y, x, y). lint( text = \"ifelse(x > 0, x, 0)\", linters = ifelse_censor_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[ifelse_censor_linter] pmax(x, y) is preferable to ifelse(x > y, x, y). # okay lint( text = \"pmin(5:1, pi)\", linters = ifelse_censor_linter() ) lint( text = \"pmax(x, 0)\", linters = ifelse_censor_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Avoid implicit assignment in function calls — implicit_assignment_linter","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"Assigning inside function calls makes code difficult read, avoided, except functions capture side-effects (e.g. capture.output()).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"implicit_assignment_linter( except = c(\"bquote\", \"expression\", \"expr\", \"quo\", \"quos\", \"quote\") )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"except character vector functions excluded linting.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"best_practices, configurable, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Avoid implicit assignment in function calls — implicit_assignment_linter","text":"","code":"# will produce lints lint( text = \"if (x <- 1L) TRUE\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. lint( text = \"mean(x <- 1:4)\", linters = implicit_assignment_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`. # okay writeLines(\"x <- 1L\\nif (x) TRUE\") #> x <- 1L #> if (x) TRUE lint( text = \"x <- 1L\\nif (x) TRUE\", linters = implicit_assignment_linter() ) writeLines(\"x <- 1:4\\nmean(x)\") #> x <- 1:4 #> mean(x) lint( text = \"x <- 1:4\\nmean(x)\", linters = implicit_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Implicit integer linter — implicit_integer_linter","title":"Implicit integer linter — implicit_integer_linter","text":"Check integers explicitly typed using form 1L instead 1.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Implicit integer linter — implicit_integer_linter","text":"","code":"implicit_integer_linter(allow_colon = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Implicit integer linter — implicit_integer_linter","text":"allow_colon Logical, default FALSE. TRUE, expressions involving : throw lint regardless whether inputs implicitly integers.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Implicit integer linter — implicit_integer_linter","text":"best_practices, configurable, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/implicit_integer_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Implicit integer linter — implicit_integer_linter","text":"","code":"# will produce lints lint( text = \"x <- 1\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. lint( text = \"x[2]\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=4::file=,line=1,col=4,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. lint( text = \"1:10\", linters = implicit_integer_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles. # okay lint( text = \"x <- 1.0\", linters = implicit_integer_linter() ) lint( text = \"x <- 1L\", linters = implicit_integer_linter() ) lint( text = \"x[2L]\", linters = implicit_integer_linter() ) lint( text = \"1:10\", linters = implicit_integer_linter(allow_colon = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that indentation is consistent — indentation_linter","title":"Check that indentation is consistent — indentation_linter","text":"Check indentation consistent","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that indentation is consistent — indentation_linter","text":"","code":"indentation_linter( indent = 2L, hanging_indent_style = c(\"tidy\", \"always\", \"never\"), assignment_as_infix = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that indentation is consistent — indentation_linter","text":"indent Number spaces, code block indented relative parent code block. Used multi-line code blocks ({ ... }), function calls (( ... )) extractions ([ ... ], [[ ... ]]). Defaults 2. hanging_indent_style Indentation style multi-line function calls arguments first line. Defaults tidyverse style, .e. block indent used function call terminates ) separate line hanging indent . Note function multi-line function calls without arguments first line always expected block-indented arguments. hanging_indent_style \"tidy\", multi-line function definitions expected double-indented first line function definition contains arguments closing parenthesis line. assignment_as_infix Treat <- regular (.e. left-associative) infix operator? means, infix operators right hand side assignment trigger second level indentation:","code":"# complies to any style map( x, f, additional_arg = 42 ) # complies to \"tidy\" and \"never\" map(x, f, additional_arg = 42 ) # complies to \"always\" map(x, f, additional_arg = 42 ) # complies to \"tidy\" and \"always\" map(x, f, additional_arg = 42) # complies to \"never\" map(x, f, additional_arg = 42) # complies to \"tidy\" function( a, b) { # body } # complies to any style variable <- a %+% b %+% c # complies to assignment_as_infix = TRUE variable <- a %+% b %+% c # complies to assignment_as_infix = FALSE variable <- a %+% b %+% c"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Check that indentation is consistent — indentation_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/indentation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check that indentation is consistent — indentation_linter","text":"","code":"# will produce lints code_lines <- \"if (TRUE) {\\n1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=0::file=,line=2,col=0,[indentation_linter] Indentation should be 2 spaces but is 0 spaces. code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter() ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"always\") ) #> ::warning file=,line=2,col=2::file=,line=2,col=2,[indentation_linter] Hanging indent should be 4 spaces but is 2 spaces. code_lines <- \"map(x, f,\\n additional_arg = 42)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42) lint( text = code_lines, linters = indentation_linter(hanging_indent_style = \"never\") ) #> ::warning file=,line=2,col=4::file=,line=2,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces. # okay code_lines <- \"map(x, f,\\n additional_arg = 42\\n)\" writeLines(code_lines) #> map(x, f, #> additional_arg = 42 #> ) lint( text = code_lines, linters = indentation_linter() ) code_lines <- \"if (TRUE) {\\n 1 + 1\\n}\" writeLines(code_lines) #> if (TRUE) { #> 1 + 1 #> } lint( text = code_lines, linters = indentation_linter(indent = 4) )"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Infix spaces linter — infix_spaces_linter","title":"Infix spaces linter — infix_spaces_linter","text":"Check infix operators surrounded spaces. Enforces corresponding Tidyverse style guide rule; see https://style.tidyverse.org/syntax.html#infix-operators.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"infix_spaces_linter(exclude_operators = NULL, allow_multiple_spaces = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Infix spaces linter — infix_spaces_linter","text":"exclude_operators Character vector operators exclude consideration linting. Default include following \"low-precedence\" operators: +, -, ~, >, >=, <, <=, ==, !=, &, &&, |, ||, <-, :=, <<-, ->, ->>, =, /, *, infix operator (exclude infixes passing \"%%\"). Note <-, :=, <<- included/excluded group (indicated passing \"<-\"), -> ->> (viz, \"->\"), = assignment setting arguments calls treated . allow_multiple_spaces Logical, default TRUE. FALSE, usage like x = 2 also linted; excluded default usage can sometimes used better code alignment, allowed style guide.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Infix spaces linter — infix_spaces_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/infix_spaces_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Infix spaces linter — infix_spaces_linter","text":"","code":"# will produce lints lint( text = \"x<-1L\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators. lint( text = \"1:4 %>%sum()\", linters = infix_spaces_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[infix_spaces_linter] Put spaces around all infix operators. # okay lint( text = \"x <- 1L\", linters = infix_spaces_linter() ) lint( text = \"1:4 %>% sum()\", linters = infix_spaces_linter() ) code_lines <- \" ab <- 1L abcdef <- 2L \" writeLines(code_lines) #> #> ab <- 1L #> abcdef <- 2L #> lint( text = code_lines, linters = infix_spaces_linter(allow_multiple_spaces = TRUE) ) lint( text = \"a||b\", linters = infix_spaces_linter(exclude_operators = \"||\") )"},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":".Date(c(, b)) logically equivalent c(.Date(), .Date(b)). equivalence holds several vectorized functions like .POSIXct() math functions like sin(). former preferred expensive part operation (.Date()) applied .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"","code":"inner_combine_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/inner_combine_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require c() to be applied before relatively expensive vectorized functions — inner_combine_linter","text":"","code":"# will produce lints lint( text = \"c(log10(x), log10(y), log10(z))\", linters = inner_combine_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[inner_combine_linter] Combine inputs to vectorized functions first to take full advantage of vectorization, e.g., log10(c(x, y)) only runs the more expensive log10() once as compared to c(log10(x), log10(y)). # okay lint( text = \"log10(c(x, y, z))\", linters = inner_combine_linter() ) lint( text = \"c(log(x, base = 10), log10(x, base = 2))\", linters = inner_combine_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":null,"dir":"Reference","previous_headings":"","what":"Is this an expression- or a file-level source object? — is_lint_level","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"Helper determining whether current source_expression contains expressions current file, just single expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"is_lint_level(source_expression, level = c(\"expression\", \"file\"))"},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"source_expression parsed expression object, .e., element object returned get_source_expressions(). level level expression tested? \"expression\" means individual expression, \"file\" means expressions current file available.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_lint_level.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Is this an expression- or a file-level source object? — is_lint_level","text":"","code":"tmp <- withr::local_tempfile(lines = c(\"x <- 1\", \"y <- x + 1\")) source_exprs <- get_source_expressions(tmp) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683447e2f1c': No such file or directory #> Error in file(con, \"r\"): cannot open the connection is_lint_level(source_exprs$expressions[[1L]], level = \"expression\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[1L]], level = \"file\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[3L]], level = \"expression\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found is_lint_level(source_exprs$expressions[[3L]], level = \"file\") #> Error in eval(expr, envir, enclos): object 'source_exprs' not found"},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":".numeric() returns TRUE typeof(x) double integer -- testing .numeric(x) || .integer(x) thus redundant.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"","code":"is_numeric_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"NB: linter plays well class_equals_linter(), can help avoid .numeric() equivalents like (class(x) == c(\"numeric\", \"integer\")).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"best_practices, consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/is_numeric_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x) — is_numeric_linter","text":"","code":"# will produce lints lint( text = \"is.numeric(y) || is.integer(y)\", linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as is.numeric(x) || is.integer(x). Use is.double(x) to test for objects stored as 64-bit floating point. lint( text = 'class(z) %in% c(\"numeric\", \"integer\")', linters = is_numeric_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as class(x) %in% c(\"integer\", \"numeric\"). Use is.double(x) to test for objects stored as 64-bit floating point. # okay lint( text = \"is.numeric(y) || is.factor(y)\", linters = is_numeric_linter() ) lint( text = 'class(z) %in% c(\"numeric\", \"integer\", \"factor\")', linters = is_numeric_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of lengths() where possible — lengths_linter","title":"Require usage of lengths() where possible — lengths_linter","text":"lengths() function added base R version 3.2.0 get length element list. equivalent sapply(x, length), faster readable.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of lengths() where possible — lengths_linter","text":"","code":"lengths_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of lengths() where possible — lengths_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lengths_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of lengths() where possible — lengths_linter","text":"","code":"# will produce lints lint( text = \"sapply(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"vapply(x, length, integer(1L))\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. lint( text = \"purrr::map_int(x, length)\", linters = lengths_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[lengths_linter] Use lengths() to find the length of each element in a list. # okay lint( text = \"lengths(x)\", linters = lengths_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Line length linter — line_length_linter","title":"Line length linter — line_length_linter","text":"Check line length comments code less length.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Line length linter — line_length_linter","text":"","code":"line_length_linter(length = 80L)"},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Line length linter — line_length_linter","text":"length maximum line length allowed. Default 80L (Hollerith limit).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Line length linter — line_length_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/line_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Line length linter — line_length_linter","text":"","code":"# will produce lints lint( text = strrep(\"x\", 23L), linters = line_length_linter(length = 20L) ) #> ::warning file=,line=1,col=21::file=,line=1,col=21,[line_length_linter] Lines should not be more than 20 characters. # okay lint( text = strrep(\"x\", 21L), linters = line_length_linter(length = 40L) )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a lint object — lint-s3","title":"Create a lint object — lint-s3","text":"Create lint object","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a lint object — lint-s3","text":"","code":"Lint( filename, line_number = 1L, column_number = 1L, type = c(\"style\", \"warning\", \"error\"), message = \"\", line = \"\", ranges = NULL, linter = \"\" )"},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a lint object — lint-s3","text":"filename path source file linted. line_number line number lint occurred. column_number column number lint occurred. type type lint. message message used describe lint error line code source lint occurred ranges list ranges line emphasized. linter deprecated. longer used.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint-s3.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a lint object — lint-s3","text":"object class c(\"lint\", \"list\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint a file, directory, or package — lint","title":"Lint a file, directory, or package — lint","text":"lint() lints single file. lint_dir() lints files directory. lint_package() lints likely locations R files package, .e. R/, tests/, inst/, vignettes/, data-raw/, demo/, exec/.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint a file, directory, or package — lint","text":"","code":"lint( filename, linters = NULL, ..., cache = FALSE, parse_settings = TRUE, text = NULL ) lint_dir( path = \".\", ..., relative_path = TRUE, exclusions = list(\"renv\", \"packrat\"), pattern = rex::rex(\".\", one_of(\"Rr\"), or(\"\", \"html\", \"md\", \"nw\", \"rst\", \"tex\", \"txt\"), end), parse_settings = TRUE ) lint_package( path = \".\", ..., relative_path = TRUE, exclusions = list(\"R/RcppExports.R\"), parse_settings = TRUE )"},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lint a file, directory, or package — lint","text":"filename either filename file lint, character string inline R code linting. latter (inline data) applies whenever filename newline character (\\n). linters named list linter functions apply. See linters full list default available linters. ... Provide additional arguments passed : exclude() (case lint(); e.g. lints exclusions) lint() (case lint_dir() lint_package(); e.g. linters cache) cache given logical, toggle caching lint results. passed character string, store cache directory. parse_settings whether try parse settings. text Optional argument supplying string lines directly, e.g. file already memory linting done ad hoc. path base directory project (lint_dir()) package (lint_package()). relative_path TRUE, file paths printed using path relative base directory. FALSE, use full absolute path. exclusions exclusions exclude(), relative package path. pattern pattern files, default take files extensions .R, .Rmd, .qmd, .Rnw, .Rhtml, .Rrst, .Rtex, .Rtxt allowing lowercase r (.r, ...).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lint a file, directory, or package — lint","text":"object class c(\"lints\", \"list\"), element \"list\" object.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Lint a file, directory, or package — lint","text":"Read vignette(\"lintr\") learn configure linters run default. Note files contain unparseable encoding problems, encoding problem linted avoid unintelligible error messages linters.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lint.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint a file, directory, or package — lint","text":"","code":"f <- withr::local_tempfile(lines = \"a=1\", fileext = \"R\") lint(f) # linting a file #> Warning: cannot open file '/tmp/RtmpSYI7YV/file16831c097810R': No such file or directory #> Error in file(con, \"r\"): cannot open the connection lint(\"a = 123\\n\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. lint(text = \"a = 123\") # linting inline-code #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. if (FALSE) { lint_dir() lint_dir( linters = list(semicolon_linter()), exclusions = list( \"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\", \"renv\" ) ) } if (FALSE) { lint_package() lint_package( linters = linters_with_defaults(semicolon_linter = semicolon_linter()), exclusions = list(\"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\") ) }"},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Available linters — linters","title":"Available linters — linters","text":"variety linters available lintr. popular ones readily accessible default_linters(). Within lint() function call, linters use initialized provided arguments fed source file (provided get_source_expressions()). data frame available linters can retrieved using available_linters(). Documentation linters structured tags allow easier discovery; see also available_tags().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Available linters — linters","text":"following tags exist: best_practices (50 linters) common_mistakes (7 linters) configurable (29 linters) consistency (18 linters) correctness (7 linters) default (25 linters) deprecated (8 linters) efficiency (23 linters) executing (5 linters) package_development (14 linters) readability (47 linters) robustness (14 linters) style (34 linters)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Available linters — linters","text":"following linters exist: absolute_path_linter (tags: best_practices, configurable, robustness) any_duplicated_linter (tags: best_practices, efficiency) any_is_na_linter (tags: best_practices, efficiency) assignment_linter (tags: configurable, consistency, default, style) backport_linter (tags: configurable, package_development, robustness) boolean_arithmetic_linter (tags: best_practices, efficiency, readability) brace_linter (tags: configurable, default, readability, style) class_equals_linter (tags: best_practices, consistency, robustness) commas_linter (tags: default, readability, style) commented_code_linter (tags: best_practices, default, readability, style) condition_message_linter (tags: best_practices, consistency) conjunct_test_linter (tags: best_practices, configurable, package_development, readability) consecutive_assertion_linter (tags: consistency, readability, style) cyclocomp_linter (tags: best_practices, configurable, default, readability, style) duplicate_argument_linter (tags: common_mistakes, configurable, correctness) empty_assignment_linter (tags: best_practices, readability) equals_na_linter (tags: common_mistakes, correctness, default, robustness) expect_comparison_linter (tags: best_practices, package_development) expect_identical_linter (tags: package_development) expect_length_linter (tags: best_practices, package_development, readability) expect_named_linter (tags: best_practices, package_development, readability) expect_not_linter (tags: best_practices, package_development, readability) expect_null_linter (tags: best_practices, package_development) expect_s3_class_linter (tags: best_practices, package_development) expect_s4_class_linter (tags: best_practices, package_development) expect_true_false_linter (tags: best_practices, package_development, readability) expect_type_linter (tags: best_practices, package_development) extraction_operator_linter (tags: best_practices, style) fixed_regex_linter (tags: best_practices, efficiency, readability) for_loop_index_linter (tags: best_practices, readability, robustness) function_argument_linter (tags: best_practices, consistency, style) function_left_parentheses_linter (tags: default, readability, style) function_return_linter (tags: best_practices, readability) ifelse_censor_linter (tags: best_practices, efficiency) implicit_assignment_linter (tags: best_practices, configurable, readability, style) implicit_integer_linter (tags: best_practices, configurable, consistency, style) indentation_linter (tags: configurable, default, readability, style) infix_spaces_linter (tags: configurable, default, readability, style) inner_combine_linter (tags: consistency, efficiency, readability) is_numeric_linter (tags: best_practices, consistency, readability) lengths_linter (tags: best_practices, efficiency, readability) line_length_linter (tags: configurable, default, readability, style) literal_coercion_linter (tags: best_practices, consistency, efficiency) matrix_apply_linter (tags: efficiency, readability) missing_argument_linter (tags: common_mistakes, configurable, correctness) missing_package_linter (tags: common_mistakes, robustness) namespace_linter (tags: configurable, correctness, executing, robustness) nested_ifelse_linter (tags: efficiency, readability) nonportable_path_linter (tags: best_practices, configurable, robustness) numeric_leading_zero_linter (tags: consistency, readability, style) object_length_linter (tags: configurable, default, executing, readability, style) object_name_linter (tags: configurable, consistency, default, executing, style) object_usage_linter (tags: configurable, correctness, default, executing, readability, style) outer_negation_linter (tags: best_practices, efficiency, readability) package_hooks_linter (tags: correctness, package_development, style) paren_body_linter (tags: default, readability, style) paste_linter (tags: best_practices, configurable, consistency) pipe_call_linter (tags: readability, style) pipe_continuation_linter (tags: default, readability, style) quotes_linter (tags: configurable, consistency, default, readability, style) redundant_equals_linter (tags: best_practices, common_mistakes, efficiency, readability) redundant_ifelse_linter (tags: best_practices, configurable, consistency, efficiency) regex_subset_linter (tags: best_practices, efficiency) routine_registration_linter (tags: best_practices, efficiency, robustness) semicolon_linter (tags: configurable, default, readability, style) seq_linter (tags: best_practices, consistency, default, efficiency, robustness) sort_linter (tags: best_practices, efficiency, readability) spaces_inside_linter (tags: default, readability, style) spaces_left_parentheses_linter (tags: default, readability, style) sprintf_linter (tags: common_mistakes, correctness) string_boundary_linter (tags: configurable, efficiency, readability) strings_as_factors_linter (tags: robustness) system_file_linter (tags: best_practices, consistency, readability) T_and_F_symbol_linter (tags: best_practices, consistency, default, readability, robustness, style) todo_comment_linter (tags: configurable, style) trailing_blank_lines_linter (tags: default, style) trailing_whitespace_linter (tags: configurable, default, style) undesirable_function_linter (tags: best_practices, configurable, efficiency, robustness, style) undesirable_operator_linter (tags: best_practices, configurable, efficiency, robustness, style) unnecessary_concatenation_linter (tags: configurable, efficiency, readability, style) unnecessary_lambda_linter (tags: best_practices, efficiency, readability) unnecessary_nested_if_linter (tags: best_practices, readability) unnecessary_placeholder_linter (tags: best_practices, readability) unreachable_code_linter (tags: best_practices, readability) unused_import_linter (tags: best_practices, common_mistakes, configurable, executing) vector_logic_linter (tags: best_practices, default, efficiency) whitespace_linter (tags: consistency, default, style) yoda_test_linter (tags: best_practices, package_development, readability)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter configuration based on defaults — linters_with_defaults","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"Make new list based lintr's default linters. result function meant passed linters argument lint(), put configuration file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"","code":"linters_with_defaults(..., defaults = default_linters) with_defaults(..., default = default_linters)"},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed. defaults, default Default list linters modify. Must named.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter configuration based on defaults — linters_with_defaults","text":"","code":"# When using interactively you will usually pass the result onto `lint` or `lint_package()` f <- withr::local_tempfile(lines = \"my_slightly_long_variable_name <- 2.3\", fileext = \"R\") lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120))) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file168355fa7765R': No such file or directory #> Error in file(con, \"r\"): cannot open the connection # the default linter list with a different line length cutoff my_linters <- linters_with_defaults(line_length_linter = line_length_linter(120)) # omit the argument name if you are just using different arguments my_linters <- linters_with_defaults(defaults = my_linters, object_name_linter(\"camelCase\")) # remove assignment checks (with NULL), add absolute path checks my_linters <- linters_with_defaults( defaults = my_linters, assignment_linter = NULL, absolute_path_linter() ) # checking the included linters names(my_linters) #> [1] \"absolute_path_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"cyclocomp_linter\" \"equals_na_linter\" #> [7] \"function_left_parentheses_linter\" \"indentation_linter\" #> [9] \"infix_spaces_linter\" \"line_length_linter\" #> [11] \"object_length_linter\" \"object_name_linter\" #> [13] \"object_usage_linter\" \"paren_body_linter\" #> [15] \"pipe_continuation_linter\" \"quotes_linter\" #> [17] \"semicolon_linter\" \"seq_linter\" #> [19] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [21] \"T_and_F_symbol_linter\" \"trailing_blank_lines_linter\" #> [23] \"trailing_whitespace_linter\" \"vector_logic_linter\" #> [25] \"whitespace_linter\""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a tag-based linter configuration — linters_with_tags","title":"Create a tag-based linter configuration — linters_with_tags","text":"Make new list based linters provided packages tagged tags. result function meant passed linters argument lint(), put configuration file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a tag-based linter configuration — linters_with_tags","text":"","code":"linters_with_tags(tags, ..., packages = \"lintr\", exclude_tags = \"deprecated\")"},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a tag-based linter configuration — linters_with_tags","text":"tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. ... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed. packages character vector packages search linters. exclude_tags Tags exclude results. Linters least one matching tag returned. except_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a tag-based linter configuration — linters_with_tags","text":"modified list linters.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/linters_with_tags.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a tag-based linter configuration — linters_with_tags","text":"","code":"# `linters_with_defaults()` and `linters_with_tags(\"default\")` are the same: all.equal(linters_with_defaults(), linters_with_tags(\"default\")) #> [1] TRUE # Get all linters useful for package development linters <- linters_with_tags(tags = c(\"package_development\", \"style\")) names(linters) #> [1] \"assignment_linter\" \"backport_linter\" #> [3] \"brace_linter\" \"commas_linter\" #> [5] \"commented_code_linter\" \"conjunct_test_linter\" #> [7] \"consecutive_assertion_linter\" \"cyclocomp_linter\" #> [9] \"expect_comparison_linter\" \"expect_identical_linter\" #> [11] \"expect_length_linter\" \"expect_named_linter\" #> [13] \"expect_not_linter\" \"expect_null_linter\" #> [15] \"expect_s3_class_linter\" \"expect_s4_class_linter\" #> [17] \"expect_true_false_linter\" \"expect_type_linter\" #> [19] \"extraction_operator_linter\" \"function_argument_linter\" #> [21] \"function_left_parentheses_linter\" \"implicit_assignment_linter\" #> [23] \"implicit_integer_linter\" \"indentation_linter\" #> [25] \"infix_spaces_linter\" \"line_length_linter\" #> [27] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [29] \"object_name_linter\" \"object_usage_linter\" #> [31] \"package_hooks_linter\" \"paren_body_linter\" #> [33] \"pipe_call_linter\" \"pipe_continuation_linter\" #> [35] \"quotes_linter\" \"semicolon_linter\" #> [37] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [39] \"T_and_F_symbol_linter\" \"todo_comment_linter\" #> [41] \"trailing_blank_lines_linter\" \"trailing_whitespace_linter\" #> [43] \"undesirable_function_linter\" \"undesirable_operator_linter\" #> [45] \"unnecessary_concatenation_linter\" \"whitespace_linter\" #> [47] \"yoda_test_linter\" # Get all linters tagged as \"default\" from lintr and mypkg if (FALSE) { linters_with_tags(\"default\", packages = c(\"lintr\", \"mypkg\")) }"},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated functions in lintr — lintr-deprecated","title":"Deprecated functions in lintr — lintr-deprecated","text":"functions deprecated lintr. open_curly_linter() closed_curly_linter() check open closed curly braces line unless follow else, comma, closing bracket. Deprecated favor brace_linter(). paren_brace_linter() checks space right parentheses opening curly brace. E.g., function(){} space, function() {} . Deprecated favor brace_linter(). semicolon_terminator_linter() checks semicolons terminate expressions. Deprecated favor semicolon_linter().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deprecated functions in lintr — lintr-deprecated","text":"","code":"closed_curly_linter(allow_single_line = FALSE) open_curly_linter(allow_single_line = FALSE) paren_brace_linter() semicolon_terminator_linter(semicolon = c(\"compound\", \"trailing\")) unneeded_concatenation_linter(allow_single_expression = TRUE) single_quotes_linter() consecutive_stopifnot_linter() no_tab_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deprecated functions in lintr — lintr-deprecated","text":"allow_single_line TRUE, allow open closed curly pair line. semicolon character vector defining semicolons report: compound Semicolons separate two statements line. trailing Semicolons following last statement line.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lintr-deprecated.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Deprecated functions in lintr — lintr-deprecated","text":"configurable, deprecated, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/lintr-package.html","id":null,"dir":"Reference","previous_headings":"","what":"Lintr — lintr-package","title":"Lintr — lintr-package","text":"Checks adherence given style, syntax errors, possible semantic issues. Supports fly checking R code edited Emacs, Vim, Sublime Text.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/lintr-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Lintr — lintr-package","text":"Maintainer: Jim Hester james.f.hester@gmail.com Authors: Florent Angly (fangly) Russ Hyde Michael Chirico Kun Ren Alexander Rosenstock (AshesITR) Indrajeet Patil patilindrajeet.science@gmail.com (ORCID) (@patilindrajeets)","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":".integer(1) (rlang::int(1)) 1L latter concise gets typed correctly compilation.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"","code":"literal_coercion_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"applies missing sentinels like NA -- typically, necessary specify storage type NA, , prefer using typed version (e.g. NA_real_) instead coercion (like .numeric(NA)).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"best_practices, consistency, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/literal_coercion_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of correctly-typed literals over literal coercions — literal_coercion_linter","text":"","code":"# will produce lints lint( text = \"int(1)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use 1L instead of int(1), i.e., use literals directly where possible, instead of coercion. lint( text = \"as.character(NA)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use NA_character_ instead of as.character(NA), i.e., use literals directly where possible, instead of coercion. lint( text = \"rlang::lgl(1L)\", linters = literal_coercion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[literal_coercion_linter] Use TRUE instead of rlang::lgl(1L), i.e., use literals directly where possible, instead of coercion. # okay lint( text = \"1L\", linters = literal_coercion_linter() ) lint( text = \"NA_character_\", linters = literal_coercion_linter() ) lint( text = \"TRUE\", linters = literal_coercion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"colSums() rowSums() clearer performant alternatives apply(x, 2, sum) apply(x, 1, sum) respectively case 2D arrays, matrices","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"matrix_apply_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/matrix_apply_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of colSums(x) or rowSums(x) over apply(x, ., sum) — matrix_apply_linter","text":"","code":"# will produce lints lint( text = \"apply(x, 1, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(x) rather than apply(x, 1, sum) lint( text = \"apply(x, 2, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x)) or colSums(x) if x has 2 dimensions rather than apply(x, 2, sum) lint( text = \"apply(x, 2, sum, na.rm = TRUE)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x, na.rm = TRUE)) or colSums(x, na.rm = TRUE) if x has 2 dimensions rather than apply(x, 2, sum, na.rm = TRUE) lint( text = \"apply(x, 2:4, sum)\", linters = matrix_apply_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[matrix_apply_linter] Use rowSums(colSums(x), dims = 3) or colSums(x) if x has 4 dimensions rather than apply(x, 2:4, sum)"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing argument linter — missing_argument_linter","title":"Missing argument linter — missing_argument_linter","text":"Check missing arguments function calls (e.g. stats::median(1:10, )).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing argument linter — missing_argument_linter","text":"","code":"missing_argument_linter( except = c(\"alist\", \"quote\", \"switch\"), allow_trailing = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Missing argument linter — missing_argument_linter","text":"except character vector function names exceptions. allow_trailing always allow trailing empty arguments?","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing argument linter — missing_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing argument linter — missing_argument_linter","text":"","code":"# will produce lints lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter() ) #> ::warning file=,line=1,col=15::file=,line=1,col=15,[missing_argument_linter] Missing argument in function call. # okay lint( text = 'tibble(x = \"a\")', linters = missing_argument_linter() ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(except = \"tibble\") ) lint( text = 'tibble(x = \"a\", )', linters = missing_argument_linter(allow_trailing = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Missing package linter — missing_package_linter","title":"Missing package linter — missing_package_linter","text":"Check missing packages library(), require(), loadNamespace(), requireNamespace() calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Missing package linter — missing_package_linter","text":"","code":"missing_package_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Missing package linter — missing_package_linter","text":"common_mistakes, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/missing_package_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Missing package linter — missing_package_linter","text":"","code":"# will produce lints lint( text = \"library(xyzxyz)\", linters = missing_package_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[missing_package_linter] Package 'xyzxyz' is not installed. # okay lint( text = \"library(stats)\", linters = missing_package_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify lintr defaults — modify_defaults","title":"Modify lintr defaults — modify_defaults","text":"Modify list defaults name, allowing replacement, deletion addition new elements.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify lintr defaults — modify_defaults","text":"","code":"modify_defaults(defaults, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify lintr defaults — modify_defaults","text":"defaults named list elements modify. ... arguments elements change. unnamed, argument automatically named. named argument already exists defaults, replaced new element. exist, added. value NULL, element removed.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify lintr defaults — modify_defaults","text":"modified list elements, sorted name. achieve sort platform-independent way, two transformations applied names: (1) replace _ 0 (2) convert tolower().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/modify_defaults.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Modify lintr defaults — modify_defaults","text":"","code":"# custom list of undesirable functions: # remove `sapply` (using `NULL`) # add `cat` (with an accompanying message), # add `print` (unnamed, i.e. with no accompanying message) # add `source` (as taken from `all_undesirable_functions`) my_undesirable_functions <- modify_defaults( defaults = default_undesirable_functions, sapply = NULL, \"cat\" = \"No cat allowed\", \"print\", all_undesirable_functions[[\"source\"]] ) # list names of functions specified as undesirable names(my_undesirable_functions) #> [1] \".libPaths\" \"attach\" \"browser\" \"cat\" #> [5] \"debug\" \"debugcall\" \"debugonce\" \"detach\" #> [9] \"library\" \"mapply\" \"options\" \"par\" #> [13] \"print\" \"require\" \"setwd\" \"sink\" #> [17] \"source\" \"Sys.setenv\" \"Sys.setlocale\" \"trace\" #> [21] \"undebug\" \"untrace\""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Namespace linter — namespace_linter","title":"Namespace linter — namespace_linter","text":"Check missing packages symbols namespace calls. Note using check_exports=TRUE check_nonexports=TRUE load packages used user code potentially change global state.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Namespace linter — namespace_linter","text":"","code":"namespace_linter(check_exports = TRUE, check_nonexports = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Namespace linter — namespace_linter","text":"check_exports Check symbol exported namespace namespace::symbol calls. check_nonexports Check symbol exists namespace namespace:::symbol calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Namespace linter — namespace_linter","text":"configurable, correctness, executing, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/namespace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Namespace linter — namespace_linter","text":"","code":"# will produce lints lint( text = \"xyzxyz::sd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[namespace_linter] Package 'xyzxyz' is not installed. lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[namespace_linter] 'ssd' is not exported from {stats}. # okay lint( text = \"stats::sd(c(1, 2, 3))\", linters = namespace_linter() ) lint( text = \"stats::ssd(c(1, 2, 3))\", linters = namespace_linter(check_exports = FALSE) ) lint( text = \"stats:::ssd(c(1, 2, 3))\", linters = namespace_linter(check_nonexports = FALSE) )"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of nested ifelse() calls — nested_ifelse_linter","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Calling ifelse() nested calls problematic two main reasons: can hard read -- mapping code expected output code can messy task/require lot mental bandwidth, especially code nests inefficient -- ifelse() can evaluate arguments yes (see https://stackoverflow.com/q/16275149); issue exacerbated nested calls","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"nested_ifelse_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"Users can instead rely readable alternative modeled SQL CASE statements, data.table::fcase() dplyr::case_when(), use look---merge approach (build mapping table values outputs merge input).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nested_ifelse_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of nested ifelse() calls — nested_ifelse_linter","text":"","code":"# will produce lints lint( text = 'ifelse(x == \"a\", 1L, ifelse(x == \"b\", 2L, 3L))', linters = nested_ifelse_linter() ) #> ::warning file=,line=1,col=22::file=,line=1,col=22,[nested_ifelse_linter] Don't use nested ifelse() calls; instead, try (1) data.table::fcase; (2) dplyr::case_when; or (3) using a lookup table. # okay lint( text = 'dplyr::case_when(x == \"a\" ~ 1L, x == \"b\" ~ 2L, TRUE ~ 3L)', linters = nested_ifelse_linter() ) lint( text = 'data.table::fcase(x == \"a\", 1L, x == \"b\", 2L, default = 3L)', linters = nested_ifelse_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Non-portable path linter — nonportable_path_linter","title":"Non-portable path linter — nonportable_path_linter","text":"Check file.path() used construct safe portable paths.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Non-portable path linter — nonportable_path_linter","text":"","code":"nonportable_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Non-portable path linter — nonportable_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/nonportable_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Non-portable path linter — nonportable_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":null,"dir":"Reference","previous_headings":"","what":"Normalize lint exclusions — normalize_exclusions","title":"Normalize lint exclusions — normalize_exclusions","text":"Normalize lint exclusions","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Normalize lint exclusions — normalize_exclusions","text":"","code":"normalize_exclusions(x, normalize_path = TRUE, root = getwd(), pattern = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Normalize lint exclusions — normalize_exclusions","text":"x Exclusion specification character vector filenames directories relative root named list integers specifying lines excluded per file named list named lists specifying linters lines excluded linters per file. normalize_path names returned exclusion list normalized paths? , relative root. root Base directory relative filename resolution. pattern non-NULL, exclude files excluded directories match pattern. Passed list.files directory excluded.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/normalize_exclusions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Normalize lint exclusions — normalize_exclusions","text":"named list file exclusions. names list specify filenames excluded. file exclusion possibly named list containing line numbers exclude, sentinel Inf completely excluded files. entry named, exclusions take effect linter name. normalize_path TRUE, file names normalized relative root. Otherwise paths left provided (relative root absolute).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":".1 0.1 mean thing, latter easier read due small size '.' glyph.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"","code":"numeric_leading_zero_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/numeric_leading_zero_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of a leading zero in all fractional numerics — numeric_leading_zero_linter","text":"","code":"# will produce lints lint( text = \"x <- .1\", linters = numeric_leading_zero_linter() ) #> ::warning file=,line=1,col=6::file=,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/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. 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_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/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] There should be 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_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_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):","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)"},{"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.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/paste_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Raise lints for several common poor usages of paste() — paste_linter","text":"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":[]},{"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 = \"\"). # 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() )"},{"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_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] `%>%` should always have a space before it 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] `|>` should always have a space before it 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/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.","code":""},{"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 conjunct_test_linter consecutive_assertion_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 implicit_assignment_linter indentation_linter infix_spaces_linter inner_combine_linter is_numeric_linter lengths_linter line_length_linter matrix_apply_linter nested_ifelse_linter numeric_leading_zero_linter object_length_linter object_usage_linter outer_negation_linter paren_body_linter pipe_call_linter pipe_continuation_linter quotes_linter redundant_equals_linter semicolon_linter sort_linter spaces_inside_linter spaces_left_parentheses_linter string_boundary_linter system_file_linter T_and_F_symbol_linter unnecessary_concatenation_linter unnecessary_lambda_linter unnecessary_nested_if_linter unnecessary_placeholder_linter unreachable_code_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_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","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/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 routine_registration_linter seq_linter strings_as_factors_linter T_and_F_symbol_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/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/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] Trailing semicolons are not needed. lint( text = \"a <- 1; b <- 1\", linters = semicolon_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[semicolon_linter] Compound semicolons are discouraged. Replace them 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] Compound semicolons are discouraged. Replace them 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] seq(length(...)) is likely to be wrong in the empty edge case. Use seq_along(...) instead. lint( text = \"1:nrow(x)\", linters = seq_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[seq_linter] 1:nrow(...) is likely to be wrong in the empty edge case. Use seq_len(nrow(...)) instead. lint( text = \"dplyr::mutate(x, .id = 1:n())\", linters = seq_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[seq_linter] 1:n() is likely to be wrong in the empty edge case. Use seq_len(n()) instead. # 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":"Require usage of sort() over .[order(.)] — sort_linter","title":"Require usage of sort() over .[order(.)] — sort_linter","text":"sort() dedicated option sort list vector. legible around twice fast .[order(.)], gap performance growing vector size.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of sort() over .[order(.)] — sort_linter","text":"","code":"sort_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/sort_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of sort() over .[order(.)] — 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":"Require usage of sort() over .[order(.)] — 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)]. 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)]. # okay lint( text = \"x[sample(order(x))]\", linters = sort_linter() ) lint( text = \"y[order(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/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","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] This code relies on the default value of stringsAsFactors, which changed in version R 4.0. Please supply an explicit value for stringsAsFactors for this code to work with versions of R both before and after this switch. # 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 consecutive_assertion_linter cyclocomp_linter extraction_operator_linter function_argument_linter function_left_parentheses_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter line_length_linter numeric_leading_zero_linter object_length_linter object_name_linter object_usage_linter package_hooks_linter paren_body_linter pipe_call_linter pipe_continuation_linter quotes_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/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\"))"},{"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 strings identify 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 # TODO\", linters = todo_comment_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[todo_comment_linter] TODO comments should be removed. lint( text = \"pi <- 1.0 # FIXME\", linters = todo_comment_linter() ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[todo_comment_linter] TODO comments should be removed. lint( text = \"x <- TRUE # hack\", linters = todo_comment_linter(todo = c(\"todo\", \"fixme\", \"hack\")) ) #> ::warning file=,line=1,col=11::file=,line=1,col=11,[todo_comment_linter] TODO comments should be removed. # 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() )"},{"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 <- withr::local_tempfile(lines = \"x <- 1\\n\") readLines(f) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file16832490bb5a': No such file or directory #> Error in file(con, \"r\"): cannot open the connection lint( filename = f, linters = trailing_blank_lines_linter() ) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file16832490bb5a': No such file or directory #> Error in file(con, \"r\"): cannot open the connection # okay f <- withr::local_tempfile(lines = \"x <- 1\") readLines(f) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683713a8442': No such file or directory #> Error in file(con, \"r\"): cannot open the connection lint( filename = f, linters = trailing_blank_lines_linter() ) #> Warning: cannot open file '/tmp/RtmpSYI7YV/file1683713a8442': No such file or directory #> Error in file(con, \"r\"): cannot open the connection"},{"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] Trailing whitespace is superfluous. 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] Trailing whitespace is superfluous. # 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 (e.g. base::return(), base::options(), base::sapply()) 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] \"Sys.setenv\" \"Sys.setlocale\" \"trace\" \"undebug\" #> [21] \"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] Function \"sapply\" is undesirable. 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] Function \"log10\" is undesirable. 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] Function \"log10\" is undesirable. 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] Function \"dir\" is undesirable. # 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] Operator `<<-` is undesirable. 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] Operator `$` is undesirable. 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] Unneeded concatenation without arguments. Replace the \"c\" call 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] Unneeded concatenation of a constant. Remove the \"c\" call. 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] Unneeded concatenation of a simple expression. Remove the \"c\" call, replacing with \"as.vector\" if using \"c\" to string 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()"},{"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, 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)). # 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() )"},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"Avoid unnecessary nested conditional statements","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"","code":"unnecessary_nested_if_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/unnecessary_nested_if_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Avoid unnecessary nested if conditional statements — unnecessary_nested_if_linter","text":"","code":"# will produce lints 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_nested_if_linter() ) #> ::warning file=,line=2,col=3::file=,line=2,col=3,[unnecessary_nested_if_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) { ... }`. # okay writeLines(\"if (x && y) { \\n return(1L) \\n}\") #> if (x && y) { #> return(1L) #> } lint( text = \"if (x && y) { \\n return(1L) \\n}\", linters = unnecessary_nested_if_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_nested_if_linter() )"},{"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 top-level return() stop() 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()"},{"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, 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] Code and comments coming after a top-level return() or stop() should be removed. # 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() )"},{"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\") )"},{"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 loading . except_packages Character vector packages ignored. usually attached side effects.","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] Package 'dplyr' 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 linters_with_tags().","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, 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] Conditional expressions require scalar logical operators (&& and ||) 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] Conditional expressions require scalar logical operators (&& and ||) # okay lint( text = \"if (TRUE && FALSE) 1\", linters = vector_logic_linter() ) lint( text = \"if (TRUE && (TRUE || FALSE)) 4\", linters = vector_logic_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/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, 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] Tests should compare objects 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] Tests should compare objects 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":".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-development-version","dir":"Changelog","previous_headings":"","what":"Bug fixes","title":"lintr (development version)","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-development-version","dir":"Changelog","previous_headings":"","what":"Changes to defaults","title":"lintr (development version)","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-development-version","dir":"Changelog","previous_headings":"","what":"New and improved features","title":"lintr (development version)","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-development-version","dir":"Changelog","previous_headings":"New and improved features","what":"New linters","title":"lintr (development version)","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-development-version","dir":"Changelog","previous_headings":"","what":"Notes","title":"lintr (development version)","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) object_usage_linter() gives helpful warning glue() expression fails evaluate (#1985, @MichaelChirico)","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 syntatic 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":""}]