diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index f5a2be1d6..6f6b32505 100644 --- a/dev/pkgdown.yml +++ b/dev/pkgdown.yml @@ -6,7 +6,7 @@ articles: creating_linters: creating_linters.html editors: editors.html lintr: lintr.html -last_built: 2024-05-20T03:42Z +last_built: 2024-05-20T22:29Z urls: reference: https://lintr.r-lib.org/reference article: https://lintr.r-lib.org/articles diff --git a/dev/reference/get_source_expressions.html b/dev/reference/get_source_expressions.html index c7a543940..b358a94d1 100644 --- a/dev/reference/get_source_expressions.html +++ b/dev/reference/get_source_expressions.html @@ -140,7 +140,7 @@
inner_combine_linter()
Note that strptime()
has one idiosyncrasy to be aware of, namely that
+auto-detected format=
is set by the first matching input, which means
+that a case like c(as.POSIXct("2024-01-01"), as.POSIXct("2024-01-01 01:02:03"))
+gives different results to as.POSIXct(c("2024-01-01", "2024-01-01 01:02:03"))
.
+This false positive is rare; a workaround where possible is to use
+consistent formatting, i.e., "2024-01-01 00:00:00"
in the example.
linters for a complete list of linters available in lintr.
f <- tempfile()
writeLines("a=1", f)
lint(f) # linting a file
-#> ::warning file=/tmp/RtmpLE85aI/file1729559b924e,line=1,col=2::file=/tmp/RtmpLE85aI/file1729559b924e,line=1,col=2,[assignment_linter] Use <-, not =, for assignment.
-#> ::warning file=/tmp/RtmpLE85aI/file1729559b924e,line=1,col=2::file=/tmp/RtmpLE85aI/file1729559b924e,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators.
+#> ::warning file=/tmp/Rtmp5ptGnu/file16a522e261c1,line=1,col=2::file=/tmp/Rtmp5ptGnu/file16a522e261c1,line=1,col=2,[assignment_linter] Use <-, not =, for assignment.
+#> ::warning file=/tmp/Rtmp5ptGnu/file16a522e261c1,line=1,col=2::file=/tmp/Rtmp5ptGnu/file16a522e261c1,line=1,col=2,[infix_spaces_linter] Put spaces around all infix operators.
lint("a = 123\n") # linting inline-code
#> ::warning file=<text>,line=1,col=3::file=<text>,line=1,col=3,[assignment_linter] Use <-, not =, for assignment.
lint(text = "a = 123") # linting inline-code
diff --git a/dev/reference/trailing_blank_lines_linter.html b/dev/reference/trailing_blank_lines_linter.html
index 5936d6b88..9d5c0dab5 100644
--- a/dev/reference/trailing_blank_lines_linter.html
+++ b/dev/reference/trailing_blank_lines_linter.html
@@ -93,7 +93,7 @@ Examples filename = f,
linters = trailing_blank_lines_linter()
)
-#> ::warning file=/tmp/RtmpLE85aI/file17294ea13a35,line=2,col=1::file=/tmp/RtmpLE85aI/file17294ea13a35,line=2,col=1,[trailing_blank_lines_linter] Remove trailing blank lines.
+#> ::warning file=/tmp/Rtmp5ptGnu/file16a54a504ee8,line=2,col=1::file=/tmp/Rtmp5ptGnu/file16a54a504ee8,line=2,col=1,[trailing_blank_lines_linter] Remove trailing blank lines.
unlink(f)
# okay
diff --git a/dev/search.json b/dev/search.json
index ef515b05c..4f0e3e66c 100644
--- a/dev/search.json
+++ b/dev/search.json
@@ -1 +1 @@
-[{"path":[]},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement michaelchirico4@gmail.com. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://lintr.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with lintr","title":"Getting help with lintr","text":"Thanks using lintr. filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"making-a-reproducible-example","dir":"","previous_headings":"","what":"Making a reproducible example","title":"Getting help with lintr","text":"Start making minimal reproducible example using reprex package. use reprex effectivly, check Get help! section tidyverse site. useful function create reprexes lintr issues lint(). can include code doesn’t lint expected linter question. example, code question contains characters need escaped, consider using raw strings instead save headache figuring multiple levels escapes.","code":"library(lintr) lint( text = \"x = 1\", linters = assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"asking-for-help","dir":"","previous_headings":"","what":"Asking for help","title":"Getting help with lintr","text":"Armed reprex, next step figure ask. ’s clarification question (e.g. don’t know exclude certain files lint workflow), start community.rstudio.com, /StackOverflow. people answer questions.","code":""},{"path":"https://lintr.r-lib.org/dev/SUPPORT.html","id":"filing-an-issue","dir":"","previous_headings":"","what":"Filing an issue","title":"Getting help with lintr","text":"’s bug, can create issue reprex. ’s false positive false negative lint, can either create issue reprex lintr repository, discuss underlying style guide respective repository. opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed. Thanks help!","code":""},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"for-packages","dir":"Articles","previous_headings":"","what":"For packages","title":"Continuous integration","text":"First, take special note proviso ?executing_linters need package dependencies installed loaded (e.g. pkgload::load_all()) order certain linters (e.g. object_usage_linter()) function intended.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions","dir":"Articles","previous_headings":"For packages","what":"GitHub Actions","title":"Continuous integration","text":"package GitHub, easiest way GitHub Actions. workflow configuration files use YAML syntax. usethis package great functionality can help workflow files. straightforward way add lintr workflow package use r-lib/actions’s lint example. usethis, need call create workflow file called lint.yaml place correct location, namely .github/workflows directory repository. file configures steps required run lintr::lint_package() package. Alternatively can use eponymous lint-changed-files.yaml lint changed files: Comments commit pull request printed annotations along side status check GitHub. want builds produce error instead just warning, can set environment variable LINTR_ERROR_ON_LINT=true. set default r-lib/actions’s lint.yaml lint-changed-files.yaml. Note kill R process case lint. project subdirectory like use GitHub Actions annotations, can set options(lintr.github_annotation_project_dir = \"path//project\") make sure annotations point correct paths.","code":"usethis::use_github_action(\"lint\") usethis::use_github_action(\"lint-changed-files\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"for-projects","dir":"Articles","previous_headings":"","what":"For projects","title":"Continuous integration","text":"limited using lintr packages – can use combination continuous integration project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"github-actions-1","dir":"Articles","previous_headings":"For projects","what":"GitHub Actions","title":"Continuous integration","text":"project GitHub, take advantage GitHub Actions usethis functionality. r-lib/actions includes lint-project example, can use calling:","code":"usethis::use_github_action(\"lint-project\")"},{"path":"https://lintr.r-lib.org/dev/articles/continuous-integration.html","id":"super-linter","dir":"Articles","previous_headings":"For projects","what":"Super-Linter","title":"Continuous integration","text":"lintr powers R lints Super-Linter MegaLinter, provide unified linting experience across many languages. Specifically, execute lintr::lint() R R Markdown files included given project.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-the-linter","dir":"Articles","previous_headings":"","what":"Writing the linter","title":"Creating new linters","text":"Describe linter, giving title briefly covering usages discouraged linter active. lines (1) generate Tags section documentation linter1; (2) link full table available linters; (3) mark function export. unfamiliar probably (1), can skipped outside lintr . Next, define name new linter. convention suffix linter names _linter. _linter functions function factories return closure actual linting function. define additional parameters useful linter function declaration (see, e.g. assignment_linter), pipe_call_linter requires additional arguments. core linter logic. xpath XPath expression expressions matching discouraged usage. xpath saved inside factory code (opposed inside linter ) efficiency. Often, xpath somewhat complicated / involve assembly code using paste() glue::glue()[^See infix_spaces_linter() example ], case preferable execute code creating linter; cached XPath re-used expression file linter run. Let’s examine XPath bit closely: Taken together, means want match expr nodes preceded %>% infix operator whose first child node name. maps pretty closely description pipe_call_linter looking , subtlety mapping R code ’re used show XML representation. expr nodes particular take practice get accustomed – use plentiful XPath-based linters lintr guide get extra practice2. Note: xml2 implements XPath 1.0, lacks helpful features available XPath 2.0. closure. called source_expression variable contains top level expressions file linted. call Linter() gives closure class ‘linter’ (also guesses name linter; see ?Linter details). raw text expression available source_file$content. However, generally possible implement linters raw text – consider equals_na_linter. just look == NA text file, ’ll generate many false positives, e.g. comments (# note: .na() proper way check == NA) inside character literals (warning(\"use == NA check missingness\")). ’re also likely generate false negatives, example == NA appear different lines! Working around issues using un-parsed text every situation amounts re-implementing parser. Therefore recommended work tokens source_file$parsed_content source_file$xml_parsed_content, tokenized R parser. tokens obtained parse() utils::getParseData() calls done prior calling new linter. getParseData() returns data.frame information source parse tree file linted. list tokens available r-source/src/main/gram.y. source_file$xml_parsed_content uses xmlparsedata::xml_parse_data() convert getParseData() output XML tree, enables writing linter logic XPath, powerful language expressing paths within nested XML data structure. linters lintr built using XPath powerful language computation abstract syntax tree / parse tree. , return early source_expression expression-level object. get_source_expression() returns object parses input file two ways – done expression--expression, contains expressions file. done facilitate caching. Suppose package long source file (e.g., 100s expressions) – rather run linters every expression every time file updated, caching activated lintr run linter expressions changed. Note check unnecessary provided linter_level = \"expression\" guarantees source_expression expression level file level. Therefore, preferable write expression-level linters whenever possible. Two types exceptions observed lintr (1) several expressions required ensure linter logic applies (e.g., conjunct_test_linter looks consecutive calls stopifnot(), typically appear consecutive expressions) (2) linter logic simple & fast compute, overhead re-running linter low (e.g., single_quotes_linter). cases, use is_lint_level(source_expression, \"file\"). source_expression$xml_parsed_content copied local variable (strictly necessary facilitates debugging). xml2::xml_find_all() used execute XPath particular expression. Keep mind typically possible single expression generate one lint – example, x %>% na.omit %>% sum trigger pipe_call_linter() twice3. Finally, pass matching XML node(s) xml_nodes_to_lints(), returns Lint objects corresponding “bad” usages found source_expression. See ?Lint ?xml_nodes_to_lints details arguments. Note , message lint always , many linters, message customized closely match observed usage. cases, xml_nodes_to_lint() can conveniently accept function lint_message takes node input converts customized message. See, example, seq_linter. efficient way implement condition (!is_lint_level(source_expression, \"expression\")).","code":"#' Pipe call linter #' #' Force explicit calls in magrittr pipes, e.g., #' `1:3 %>% sum()` instead of `1:3 %>% sum`. #' @evalRd rd_tags(\"pipe_call_linter\") #' @seealso [linters] for a complete list of linters available in lintr. #' @export pipe_call_linter <- function() { xpath <- \"//expr[preceding-sibling::SPECIAL[text() = '%>%'] and *[1][self::SYMBOL]]\" //expr # global search (//) for 'expr' nodes (R expressions), at any nesting level [ # node[...] looks for any 'node' satisfying conditions in ... preceding-sibling:: # \"siblings\" are at the same nesting level in XML SPECIAL[ # 'SPECIAL' is the parse token for infix operators like %% or %+% text() = '%>%' # text() returns the string associated with this node ] # and # combine conditions with 'and' * # match any node [1] # match the first such node [self::SYMBOL] # match if the current node is a 'SYMBOL' (i.e., a 'name' in R) ] # Linter(function(source_expression) { if (!is_lint_level(source_expression, \"expression\")) { return(list()) } xml <- source_expression$xml_parsed_content bad_expr <- xml2::xml_find_all(xml, xpath) xml_nodes_to_lints( bad_expr, source_expression = source_expression, lint_message = \"Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`.\", type = \"warning\" ) linter_level = \"expression\""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"writing-linter-tests","dir":"Articles","previous_headings":"","what":"Writing linter tests","title":"Creating new linters","text":"(NB: section uses assignment_linter() simpler examples pipe_continuation_linter().) lintr works best inside testthat unit testing framework, particular, lintr exports lintr::expect_lint() designed companion testthat expectations. can define tests inside separate test_that calls. linters use default form. test series expectations linter using expect_lint. Please see ?expect_lint full description parameters. main three aspects test : Linter returns lints nothing lint, e.g. Linter returns lint something lint, e.g. many edge cases can think might break , e.g. may want test additional lint attributes correct, type, line number, column number, e.g. Finally, good idea test linter reports multiple lints needed, e.g. always better write many tests rather .","code":"test_that(\"returns the correct linting\", { expect_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. xml_find_function_calls(): Whenever linter needs query R function calls, e.g. via XPath //SYMBOL_FUNCTION_CALL[text() = 'myfun'], use member source_expression obtain function call nodes efficiently. Instead use make_linter_from_xpath() make_linter_from_function_xpath(): Whenever linter can expressed static XPath static message, use make_linter_from_xpath() , XPath starts //SYMBOL_FUNCTION_CALL, use make_linter_from_function_xpath(). Instead make_linter_from_xpath(xpath = \"//SYMBOL_FUNCTION_CALL[text() = 'foo' text() = 'bar']/cond\"), use make_linter_from_function_xpath(function_names = c(\"foo\", \"bar\"), xpath = \"cond\").","code":"xml <- source_expression$xml_parsed_content xpath <- \"//SYMBOL_FUNCTION_CALL[text() = 'myfun']/parent::expr/some/cond\" xml_find_all(xml, xpath) xml_calls <- source_expression$xml_find_function_calls(\"myfun\") call_xpath <- \"parent::expr/some/cond\" xml_find_all(xml_calls, call_xpath)"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"more-details-about-writing-tests-for-new-lintr-linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"More details about writing tests for new {lintr} linters","title":"Creating new linters","text":"lintr package uses testthat testing. can run currently available tests using devtools::test(). want run tests given file use filter argument devtools::test(). Linter tests put tests/testthat/ folder. test filename linter name prefixed test-, e.g. test-pipe_continuation_linter.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"adding-your-linter-to-the-default_linters","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Adding your linter to the default_linters","title":"Creating new linters","text":"linter implements part tidyverse style guide can add default_linters. object created file zzz.R (name ensures always run linters defined). Add linter name default_linters list NULL end, add corresponding test case test script ./tests/testthat/default_linter_testcode.R.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/creating_linters.html","id":"submit-pull-request","dir":"Articles","previous_headings":"Contributing to {lintr}","what":"Submit pull request","title":"Creating new linters","text":"Push changes branch fork lintr repository, submit pull request get linter merged lintr!","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"rstudio","dir":"Articles","previous_headings":"","what":"RStudio","title":"Editor setup","text":"lintr lints automatically displayed RStudio Markers pane (RStudio versions > v0.99.206). order show “Markers” pane RStudio: Menu “Tools” -> “Global Options…”, window title “Options” pop . window: click “Code” left; click “Diagnostics” tab; check “Show diagnostics R”. lint source file test.R type Console lintr::lint(\"test.R\") look result “Markers” pane. package also includes two addins linting current source package. bind addin keyboard shortcut navigate Tools > addins > Browse Addins > Keyboard Shortcuts. ’s recommended use Alt+Shift+L linting current source lint Ctrl+Shift+Alt+L code package. easy remember Alt+Shift+L(int) ;)","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"emacs","dir":"Articles","previous_headings":"","what":"Emacs","title":"Editor setup","text":"lintr built-integration flycheck versions greater 0.23.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation","dir":"Articles","previous_headings":"Emacs","what":"Installation","title":"Editor setup","text":"lintr fully integrated flycheck using ESS. See installation documentation packages information.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration","dir":"Articles","previous_headings":"Emacs","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff. - M-x customize-option -> flycheck-lintr-linters -> linters_with_defaults(line_length_linter(120))","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---syntastic","dir":"Articles","previous_headings":"","what":"Vim - syntastic","title":"Editor setup","text":"lintr can integrated syntastic --fly linting.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Installation","title":"Editor setup","text":"Put file syntastic/lintr.vim syntastic/syntax_checkers/r. using pathogen directory ~/.vim/bundles/syntastic/syntax_checkers/r. also need add following lines .vimrc.","code":"let g:syntastic_enable_r_lintr_checker = 1 let g:syntastic_r_checkers = ['lintr']"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-1","dir":"Articles","previous_headings":"Vim - syntastic","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. using different line length cutoff.","code":"let g:syntastic_r_lintr_linters = \"linters_with_defaults(line_length_linter(120))\""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"vim---ale","dir":"Articles","previous_headings":"","what":"Vim - ALE","title":"Editor setup","text":"lintr can integrated ALE fly linting.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Installation","title":"Editor setup","text":"lintr integrated ALE requires additional installation.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-2","dir":"Articles","previous_headings":"Vim - ALE","what":"Configuration","title":"Editor setup","text":"can configure linters used, e.g. using different line length cutoff. can also configure whether lint lint_package used. Set 1 lint_package 0 (default) lint. See :h ale_r_lintr information. Note configuration .lintr files supported. work around can used read contents .lintr file root working directory. allow use configuration .lintr files.","code":"let g:ale_r_lintr_options = \"linters_with_defaults(line_length_linter(120))\" let g:ale_r_lintr_lint_package = 1 if filereadable(\".lintr\") let g:ale_r_lintr_options = join(readfile('.lintr')) endif"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"sublime-text-3","dir":"Articles","previous_headings":"","what":"Sublime Text 3","title":"Editor setup","text":"lintr can integrated Sublime Linter --fly linting.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Installation","title":"Editor setup","text":"Simply install sublimeLinter-contrib-lintr using Package Control. information see Sublime Linter Docs","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"configuration-3","dir":"Articles","previous_headings":"Sublime Text 3","what":"Configuration","title":"Editor setup","text":"can also configure linters used. e.g. disabling assignment linter using different line length cutoff. SublimeLinter User Settings","code":"{ \"linters\": { \"lintr\": { \"linters\": \"linters_with_defaults(assignment_linter = NULL, line_length_linter(120))\" } } }"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"atom","dir":"Articles","previous_headings":"","what":"Atom","title":"Editor setup","text":"lintr can integrated Linter fly linting.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-4","dir":"Articles","previous_headings":"Atom","what":"Installation","title":"Editor setup","text":"Simply install linter-lintr within Atom command line : information bug reports see Atom linter-lintr.","code":"apm install linter-lintr"},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"visual-studio-code","dir":"Articles","previous_headings":"","what":"Visual Studio Code","title":"Editor setup","text":"Visual Studio Code, vscode-R presents lintr diagnostics languageserver.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/editors.html","id":"installation-5","dir":"Articles","previous_headings":"Visual Studio Code","what":"Installation","title":"Editor setup","text":"Installing languageserver package R vscode-R extension VS Code enable lintr VS Code default run following command lines:","code":"Rscript -e 'install.packages(\"languageserver\")' code --install-extension reditorsupport.r"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"running-lintr-on-a-project","dir":"Articles","previous_headings":"","what":"Running lintr on a project","title":"Using lintr","text":"Checking R project lints can done three different functions: Lint single file using lint(): Lint directory using lint_dir(): apply lint() R source files matching pattern argument. default, means .R files well knitr formats (e.g. .Rmd, .Rnw). lint_dir vectorized path, multiple directories can linted time. Lint relevant directories R package using lint_package(): apply lint_dir() subdirectories usually containing R code packages: R containing package implementation. tests containing test code. inst containing sample code vignettes installed along package. vignettes containing package vignettes. data-raw containing code produce data files. information assumed package structure, see R Packages. Note linters (e.g. object_usage_linter()) require package installed function properly. pkgload::load_all() also suffice. See ?executing_linters details.","code":"lint(filename = \"R/bad.R\") lint_dir(path = \"R\") lint_package(path = \".\")"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"the--lintr-file","dir":"Articles","previous_headings":"Configuring linters","what":"The .lintr file","title":"Using lintr","text":"canonical way configure R projects packages linting create .lintr file project root. file debian control format (?read.dcf), value evaluated R code lintr reading settings. minimal .lintr file can generated running use_lintr() project directory. Lintr supports per-project configuration following fields. linters - see ?linters_with_defaults example specifying non-default linters ?linters_with_tags fine-grained control. exclusions - list filenames exclude linting. can use named item exclude certain lines file. exclude - regex pattern lines exclude linting. Default “# nolint” exclude_start - regex pattern start exclusion range. Default “# nolint start” exclude_end - regex pattern end exclusion range. Default “# nolint end” encoding - encoding used source files. Default inferred .Rproj DESCRIPTION files, fallback UTF-8","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"lintr-file-example","dir":"Articles","previous_headings":"Configuring linters","what":".lintr File Example","title":"Using lintr","text":"example .lintr file uses 120 character line lengths, disables commented_code_linter, excludes couple files.","code":"linters: linters_with_defaults( line_length_linter(120), commented_code_linter = NULL ) exclusions: list( \"inst/doc/creating_linters.R\" = 1, \"inst/example/bad.R\", \"tests/testthat/exclusions-test\" )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"other-configuration-options","dir":"Articles","previous_headings":"Configuring linters","what":"Other configuration options","title":"Using lintr","text":"generally, lintr searches settings file according following prioritized list. first one found, , used: options(\"lintr.linter_file\") absolute path, file used. default option \".lintr\" value environment variable R_LINTR_LINTER_FILE, set. linter file (, file named like lintr.linter_file) currently-searched directory, .e. directory file passed lint(); linter file .github/linters child directory currently-searched directory. project-local linter file closest parent directory currently-searched directory, starting deepest path, moving upwards one level time. run lint_package(), directory can differ linted file. linter file user’s HOME directory. linter file called config user’s configuration path (given tools::R_user_dir(\"lintr\", = \"config\")). linter file found, default settings take effect (see defaults).","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-options","dir":"Articles","previous_headings":"Configuring linters","what":"Using options()","title":"Using lintr","text":"Values options(), NULL, take precedence linter file (e.g. .lintr). Note key option_name linter file translates R option lintr.option_name. example, options(lintr.exclude = \"# skip lint\") take precedence exclude: # nolint linter file.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-arguments-to-lint","dir":"Articles","previous_headings":"Configuring linters","what":"Using arguments to lint()","title":"Using lintr","text":"settings can also passed arguments linting functions directly. case exclusions, combined globally parsed settings. settings overridden. specified settings changed, remaining settings taken directly defaults, argument parse_settings = FALSE can added function calls. suppress reading .lintr configuration. particularly useful tests exclude example files containing lints package-level .lintr excludes files lints intentional.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"defaults","dir":"Articles","previous_headings":"Configuring linters","what":"Defaults","title":"Using lintr","text":"default settings lintr intended conform tidyverse style guide. However, behavior can customized using different methods. Apart lintr.linter_file, defaults \".lintr\", following settings: Note default encoding setting depends file linted. Encoding found .Rproj file DESCRIPTION file, encoding overrides default UTF-8.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"customizing-active-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Customizing active linters","title":"Using lintr","text":"want customize linters, can use helper function linters_with_defaults(), keep unnamed linters default settings. Disable linter passing NULL. example, set line length limit 120 characters globally disable whitespace_linter(), can put .lintr: default, following linters enabled. applicable, default settings also shown. Another way customize linters specifying tags linters_with_tags(). available tags listed : can select tags interest see linters included: can include tag-based linters configuration file, customize :","code":"linters: linters_with_defaults( line_length_linter = line_length_linter(120L), whitespace_linter = NULL ) lintr::available_tags(packages = \"lintr\") #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"pkg_testthat\" \"readability\" #> [13] \"regex\" \"robustness\" \"style\" #> [16] \"tidy_design\" linters <- lintr::linters_with_tags(tags = c(\"package_development\", \"readability\")) names(linters) #> [1] \"backport_linter\" \"boolean_arithmetic_linter\" #> [3] \"brace_linter\" \"commas_linter\" #> [5] \"commented_code_linter\" \"comparison_negation_linter\" #> [7] \"conjunct_test_linter\" \"consecutive_assertion_linter\" #> [9] \"consecutive_mutate_linter\" \"cyclocomp_linter\" #> [11] \"empty_assignment_linter\" \"expect_comparison_linter\" #> [13] \"expect_identical_linter\" \"expect_length_linter\" #> [15] \"expect_named_linter\" \"expect_not_linter\" #> [17] \"expect_null_linter\" \"expect_s3_class_linter\" #> [19] \"expect_s4_class_linter\" \"expect_true_false_linter\" #> [21] \"expect_type_linter\" \"fixed_regex_linter\" #> [23] \"for_loop_index_linter\" \"function_left_parentheses_linter\" #> [25] \"function_return_linter\" \"if_not_else_linter\" #> [27] \"if_switch_linter\" \"implicit_assignment_linter\" #> [29] \"indentation_linter\" \"infix_spaces_linter\" #> [31] \"inner_combine_linter\" \"is_numeric_linter\" #> [33] \"keyword_quote_linter\" \"length_levels_linter\" #> [35] \"lengths_linter\" \"library_call_linter\" #> [37] \"line_length_linter\" \"matrix_apply_linter\" #> [39] \"nested_ifelse_linter\" \"nested_pipe_linter\" #> [41] \"numeric_leading_zero_linter\" \"object_length_linter\" #> [43] \"object_overwrite_linter\" \"object_usage_linter\" #> [45] \"one_call_pipe_linter\" \"outer_negation_linter\" #> [47] \"package_hooks_linter\" \"paren_body_linter\" #> [49] \"pipe_call_linter\" \"pipe_consistency_linter\" #> [51] \"pipe_continuation_linter\" \"quotes_linter\" #> [53] \"redundant_equals_linter\" \"rep_len_linter\" #> [55] \"repeat_linter\" \"sample_int_linter\" #> [57] \"scalar_in_linter\" \"semicolon_linter\" #> [59] \"sort_linter\" \"spaces_inside_linter\" #> [61] \"spaces_left_parentheses_linter\" \"stopifnot_all_linter\" #> [63] \"string_boundary_linter\" \"system_file_linter\" #> [65] \"T_and_F_symbol_linter\" \"unnecessary_concatenation_linter\" #> [67] \"unnecessary_lambda_linter\" \"unnecessary_nesting_linter\" #> [69] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [71] \"which_grepl_linter\" \"yoda_test_linter\" linters: linters_with_tags( tags = c(\"package_development\", \"readability\"), yoda_test_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"using-all-available-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Using all available linters","title":"Using lintr","text":"default lintr configuration includes linters relevant tidyverse style guide, many linters available lintr. can see list available linters using want use available linters, can include .lintr file: want use available linters except , can exclude using NULL:","code":"names(lintr::all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"comparison_negation_linter\" \"condition_call_linter\" #> [13] \"condition_message_linter\" \"conjunct_test_linter\" #> [15] \"consecutive_assertion_linter\" \"consecutive_mutate_linter\" #> [17] \"cyclocomp_linter\" \"duplicate_argument_linter\" #> [19] \"empty_assignment_linter\" \"equals_na_linter\" #> [21] \"expect_comparison_linter\" \"expect_identical_linter\" #> [23] \"expect_length_linter\" \"expect_named_linter\" #> [25] \"expect_not_linter\" \"expect_null_linter\" #> [27] \"expect_s3_class_linter\" \"expect_s4_class_linter\" #> [29] \"expect_true_false_linter\" \"expect_type_linter\" #> [31] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [33] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [35] \"function_return_linter\" \"if_not_else_linter\" #> [37] \"if_switch_linter\" \"ifelse_censor_linter\" #> [39] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [41] \"indentation_linter\" \"infix_spaces_linter\" #> [43] \"inner_combine_linter\" \"is_numeric_linter\" #> [45] \"keyword_quote_linter\" \"length_levels_linter\" #> [47] \"length_test_linter\" \"lengths_linter\" #> [49] \"library_call_linter\" \"line_length_linter\" #> [51] \"list_comparison_linter\" \"literal_coercion_linter\" #> [53] \"matrix_apply_linter\" \"missing_argument_linter\" #> [55] \"missing_package_linter\" \"namespace_linter\" #> [57] \"nested_ifelse_linter\" \"nested_pipe_linter\" #> [59] \"nonportable_path_linter\" \"nrow_subset_linter\" #> [61] \"numeric_leading_zero_linter\" \"nzchar_linter\" #> [63] \"object_length_linter\" \"object_name_linter\" #> [65] \"object_overwrite_linter\" \"object_usage_linter\" #> [67] \"one_call_pipe_linter\" \"outer_negation_linter\" #> [69] \"package_hooks_linter\" \"paren_body_linter\" #> [71] \"paste_linter\" \"pipe_call_linter\" #> [73] \"pipe_consistency_linter\" \"pipe_continuation_linter\" #> [75] \"pipe_return_linter\" \"print_linter\" #> [77] \"quotes_linter\" \"redundant_equals_linter\" #> [79] \"redundant_ifelse_linter\" \"regex_subset_linter\" #> [81] \"rep_len_linter\" \"repeat_linter\" #> [83] \"return_linter\" \"routine_registration_linter\" #> [85] \"sample_int_linter\" \"scalar_in_linter\" #> [87] \"semicolon_linter\" \"seq_linter\" #> [89] \"sort_linter\" \"spaces_inside_linter\" #> [91] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [93] \"stopifnot_all_linter\" \"string_boundary_linter\" #> [95] \"strings_as_factors_linter\" \"system_file_linter\" #> [97] \"T_and_F_symbol_linter\" \"terminal_close_linter\" #> [99] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [101] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [103] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [105] \"unnecessary_lambda_linter\" \"unnecessary_nesting_linter\" #> [107] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [109] \"unused_import_linter\" \"vector_logic_linter\" #> [111] \"which_grepl_linter\" \"whitespace_linter\" #> [113] \"yoda_test_linter\" linters: all_linters() linters: all_linters( commented_code_linter = NULL, implicit_integer_linter = NULL )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"advanced-programmatic-retrieval-of-linters","dir":"Articles","previous_headings":"Configuring linters > Defaults","what":"Advanced: programmatic retrieval of linters","title":"Using lintr","text":"use cases, may useful specify linters string instead name, .e. \"assignment_linter\" instead writing assignment_linter(). Beware cases, simple get() enough:","code":"library(lintr) linter_name <- \"assignment_linter\" show_lint <- function(l) { lint_df <- as.data.frame(l) print(lint_df[, c(\"line_number\", \"message\", \"linter\")]) } hline <- function() cat(strrep(\"-\", getOption(\"width\") - 5L), \"\\n\", sep = \"\") withr::with_tempfile(\"tmp\", { writeLines(\"a = 1\", tmp) # linter column is just 'get' show_lint(lint(tmp, linters = get(linter_name)())) hline() this_linter <- get(linter_name)() attr(this_linter, \"name\") <- linter_name # linter column is 'assignment_linter' show_lint(lint(tmp, linters = this_linter)) hline() # more concise alternative for this case: use eval(call(.)) show_lint(lint(tmp, linters = eval(call(linter_name)))) }) #> line_number message linter #> 1 1 Use <-, not =, for assignment. get #> --------------------------------------------------------------------------- #> line_number message linter #> 1 1 Use <-, not =, for assignment. assignment_linter #> --------------------------------------------------------------------------- #> line_number message linter #> 1 1 Use <-, not =, for assignment. assignment_linter"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"exclusions","dir":"Articles","previous_headings":"","what":"Exclusions","title":"Using lintr","text":"Sometimes, linters globally disabled. Instead, one might want exclude code linting altogether selectively disable linters part code. Note preferred way excluding lints source code use narrowest possible scope specify exactly linters throw lint marked line. prevents accidental suppression justified lints happen line lint needs suppressed.","code":""},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-of-code","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines of code","title":"Using lintr","text":"Within source files, special comments can used exclude single lines code linting. lints produced marked line excluded results. default, special comment # nolint: file.R > lint(\"file.R\") file2.R > lint(\"file2.R\") Observe lints suppressed output shown. Sometimes, specific linter needs excluded. case, name linter can appended # nolint comment preceded colon terminated dot.","code":"X = 42L # -------------- this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=1::file=,line=1,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 81 characters. X = 42L # nolint ------ this comment overflows the default 80 chars line length."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-only-some-linters","dir":"Articles","previous_headings":"Exclusions","what":"Excluding only some linters","title":"Using lintr","text":"file3.R > lint(\"file3.R\") Observe object_name_linter suppressed. preferable blanket # nolint statements blanket exclusions may accidentally silence linter intentionally suppressed. Multiple linters can specified listing comma separator: file4.R > lint(\"file4.R\") can also specify linter names unique prefix instead full name: file5.R > lint(\"file5.R\")","code":"X = 42L # nolint: object_name_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. #> ::warning file=,line=1,col=81::file=,line=1,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 94 characters. X = 42L # nolint: object_name_linter, line_length_linter. this comment overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. X = 42L # nolint: object_name, line_len. this comment still overflows the default 80 chars line length. #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment."},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-multiple-lines-of-codes","dir":"Articles","previous_headings":"Exclusions","what":"Excluding multiple lines of codes","title":"Using lintr","text":"linters disabled contiguous block code, exclude_start exclude_end patterns can used. default # nolint start # nolint end respectively. # nolint start accepts syntax # nolint disable specific linters following lines # nolint end encountered. (lints)","code":"# x <- 42L # print(x) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Remove commented code. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[commented_code_linter] Remove commented code. # nolint start: commented_code_linter. # x <- 42L # print(x) # nolint end"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-lines-via-the-config-file","dir":"Articles","previous_headings":"Exclusions","what":"Excluding lines via the config file","title":"Using lintr","text":"Individual lines can also excluded via config file setting key exclusions list elements corresponding different files. exclude lints line 1 file R/bad.R line_length_linter lines 4 6 file, one can set paths interpreted relative location .lintr file.","code":"exclusions: list( \"R/bad.R\" = list( 1, # global exclusions are unnamed line_length_linter = 4:6 ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-files-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding files completely","title":"Using lintr","text":"linter configuration can also used exclude file entirely, linter file entirely. Use sentinel line number Inf mark lines excluded within file. file given character vector, full exclusion implied.","code":"exclusions: list( # excluded from all lints: \"R/excluded1.R\", \"R/excluded2.R\" = Inf, \"R/excluded3.R\" = list(Inf), # excluded from line_length_linter: \"R/no-line-length.R\" = list( line_length_linter = Inf ) )"},{"path":"https://lintr.r-lib.org/dev/articles/lintr.html","id":"excluding-directories-completely","dir":"Articles","previous_headings":"Exclusions","what":"Excluding directories completely","title":"Using lintr","text":"Entire directories also recognized supplied strings exclusions key. example, exclude renv folder linting R project using renv, set particularly useful projects include external code subdirectories.","code":"exclusions: list( \"renv\" )"},{"path":"https://lintr.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Jim Hester. Author. Florent Angly. Author. fangly Russ Hyde. Author. Michael Chirico. Author, maintainer. Kun Ren. Author. Alexander Rosenstock. Author. AshesITR Indrajeet Patil. Author. @patilindrajeets","code":""},{"path":"https://lintr.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hester J, Angly F, Hyde R, Chirico M, Ren K, Rosenstock , Patil (2024). lintr: 'Linter' R Code. R package version 3.1.2.9000, https://github.com/r-lib/lintr, https://lintr.r-lib.org.","code":"@Manual{, title = {lintr: A 'Linter' for R Code}, author = {Jim Hester and Florent Angly and Russ Hyde and Michael Chirico and Kun Ren and Alexander Rosenstock and Indrajeet Patil}, year = {2024}, note = {R package version 3.1.2.9000, https://github.com/r-lib/lintr}, url = {https://lintr.r-lib.org}, }"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"lintr","dir":"","previous_headings":"","what":"A Linter for R Code","title":"A Linter for R Code","text":"lintr provides static code analysis R. checks adherence given style, identifying syntax errors possible semantic issues, reports can take action. Watch lintr action following animation: lintr complementary {styler} package automatically restyles code, eliminating problems lintr can detect.","code":""},{"path":"https://lintr.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"A Linter for R Code","text":"Install stable version CRAN: development version GitHub:","code":"install.packages(\"lintr\") # install.packages(\"remotes\") remotes::install_github(\"r-lib/lintr\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"A Linter for R Code","text":"can create configuration file run selected linters: see list linters included configuration:","code":"lintr::use_lintr(type = \"tidyverse\") # in a project: lintr::lint_dir() # in a package: lintr::lint_package() # tidyverse (default) names(lintr::linters_with_defaults()) # full names(lintr::all_linters())"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"setting-up-github-actions","dir":"","previous_headings":"Usage","what":"Setting up GitHub Actions","title":"A Linter for R Code","text":"usethis provides helper functions generate lint workflows GitHub Actions: can also run lintr continuous integration within IDE text editor. See vignette(\"continuous-integration\") vignette(\"editors\") details. Without configuration, run default linters. See vignette(\"lintr\") learn modify defaults.","code":"# in a project: usethis::use_github_action(\"lint-project\") # in a package: usethis::use_github_action(\"lint\")"},{"path":"https://lintr.r-lib.org/dev/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"A Linter for R Code","text":"Please note lintr project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a linter closure — Linter","title":"Create a linter closure — Linter","text":"Create linter closure","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a linter closure — Linter","text":"","code":"Linter( fun, name = linter_auto_name(), linter_level = c(NA_character_, \"file\", \"expression\") )"},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a linter closure — Linter","text":"fun function takes source file returns lint objects. name Default name Linter. Lints produced linter labelled name default. linter_level level expression linter working ? \"expression\" means individual expression xml_parsed_content, \"file\" means expressions current file available full_xml_parsed_content. NA means linter run , expression-level file-level source expressions.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/Linter.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a linter closure — Linter","text":"function class set 'linter'.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"T and F symbol linter — T_and_F_symbol_linter","title":"T and F symbol linter — T_and_F_symbol_linter","text":"Although can synonyms, avoid symbols T F, use TRUE FALSE, respectively, instead. T F reserved keywords can assigned values.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"T_and_F_symbol_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"T and F symbol linter — T_and_F_symbol_linter","text":"best_practices, consistency, default, readability, robustness, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/T_and_F_symbol_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"T and F symbol linter — T_and_F_symbol_linter","text":"","code":"# will produce lints lint( text = \"x <- T; y <- F\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[T_and_F_symbol_linter] Use TRUE instead of the symbol T. #> ::warning file=,line=1,col=15::file=,line=1,col=15,[T_and_F_symbol_linter] Use FALSE instead of the symbol F. lint( text = \"T = 1.2; F = 2.4\", linters = T_and_F_symbol_linter() ) #> ::warning file=,line=1,col=2::file=,line=1,col=2,[T_and_F_symbol_linter] Don't use T as a variable name, as it can break code relying on T being TRUE. #> ::warning file=,line=1,col=11::file=,line=1,col=11,[T_and_F_symbol_linter] Don't use F as a variable name, as it can break code relying on F being FALSE. # okay lint( text = \"x <- c(TRUE, FALSE)\", linters = T_and_F_symbol_linter() ) lint( text = \"t = 1.2; f = 2.4\", linters = T_and_F_symbol_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Absolute path linter — absolute_path_linter","title":"Absolute path linter — absolute_path_linter","text":"Check absolute paths used (e.g. \"/var\", \"C:\\System\", \"~/docs\").","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Absolute path linter — absolute_path_linter","text":"","code":"absolute_path_linter(lax = TRUE)"},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Absolute path linter — absolute_path_linter","text":"lax Less stringent linting, leading fewer false positives. TRUE, lint path strings, contain least two path elements, one least two characters contain alphanumeric chars (including UTF-8), spaces, win32-allowed punctuation","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Absolute path linter — absolute_path_linter","text":"best_practices, configurable, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/absolute_path_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Absolute path linter — absolute_path_linter","text":"","code":"# 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":"... Arguments elements change. unnamed, argument automatically named. named argument already exists list linters, replaced new element. exist, added. value NULL, linter removed. packages character vector packages search linters.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/all_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a linter configuration based on all available linters — all_linters","text":"","code":"names(all_linters()) #> [1] \"absolute_path_linter\" \"any_duplicated_linter\" #> [3] \"any_is_na_linter\" \"assignment_linter\" #> [5] \"backport_linter\" \"boolean_arithmetic_linter\" #> [7] \"brace_linter\" \"class_equals_linter\" #> [9] \"commas_linter\" \"commented_code_linter\" #> [11] \"comparison_negation_linter\" \"condition_call_linter\" #> [13] \"condition_message_linter\" \"conjunct_test_linter\" #> [15] \"consecutive_assertion_linter\" \"consecutive_mutate_linter\" #> [17] \"cyclocomp_linter\" \"duplicate_argument_linter\" #> [19] \"empty_assignment_linter\" \"equals_na_linter\" #> [21] \"expect_comparison_linter\" \"expect_identical_linter\" #> [23] \"expect_length_linter\" \"expect_named_linter\" #> [25] \"expect_not_linter\" \"expect_null_linter\" #> [27] \"expect_s3_class_linter\" \"expect_s4_class_linter\" #> [29] \"expect_true_false_linter\" \"expect_type_linter\" #> [31] \"fixed_regex_linter\" \"for_loop_index_linter\" #> [33] \"function_argument_linter\" \"function_left_parentheses_linter\" #> [35] \"function_return_linter\" \"if_not_else_linter\" #> [37] \"if_switch_linter\" \"ifelse_censor_linter\" #> [39] \"implicit_assignment_linter\" \"implicit_integer_linter\" #> [41] \"indentation_linter\" \"infix_spaces_linter\" #> [43] \"inner_combine_linter\" \"is_numeric_linter\" #> [45] \"keyword_quote_linter\" \"length_levels_linter\" #> [47] \"length_test_linter\" \"lengths_linter\" #> [49] \"library_call_linter\" \"line_length_linter\" #> [51] \"list_comparison_linter\" \"literal_coercion_linter\" #> [53] \"matrix_apply_linter\" \"missing_argument_linter\" #> [55] \"missing_package_linter\" \"namespace_linter\" #> [57] \"nested_ifelse_linter\" \"nested_pipe_linter\" #> [59] \"nonportable_path_linter\" \"nrow_subset_linter\" #> [61] \"numeric_leading_zero_linter\" \"nzchar_linter\" #> [63] \"object_length_linter\" \"object_name_linter\" #> [65] \"object_overwrite_linter\" \"object_usage_linter\" #> [67] \"one_call_pipe_linter\" \"outer_negation_linter\" #> [69] \"package_hooks_linter\" \"paren_body_linter\" #> [71] \"paste_linter\" \"pipe_call_linter\" #> [73] \"pipe_consistency_linter\" \"pipe_continuation_linter\" #> [75] \"pipe_return_linter\" \"print_linter\" #> [77] \"quotes_linter\" \"redundant_equals_linter\" #> [79] \"redundant_ifelse_linter\" \"regex_subset_linter\" #> [81] \"rep_len_linter\" \"repeat_linter\" #> [83] \"return_linter\" \"routine_registration_linter\" #> [85] \"sample_int_linter\" \"scalar_in_linter\" #> [87] \"semicolon_linter\" \"seq_linter\" #> [89] \"sort_linter\" \"spaces_inside_linter\" #> [91] \"spaces_left_parentheses_linter\" \"sprintf_linter\" #> [93] \"stopifnot_all_linter\" \"string_boundary_linter\" #> [95] \"strings_as_factors_linter\" \"system_file_linter\" #> [97] \"T_and_F_symbol_linter\" \"terminal_close_linter\" #> [99] \"todo_comment_linter\" \"trailing_blank_lines_linter\" #> [101] \"trailing_whitespace_linter\" \"undesirable_function_linter\" #> [103] \"undesirable_operator_linter\" \"unnecessary_concatenation_linter\" #> [105] \"unnecessary_lambda_linter\" \"unnecessary_nesting_linter\" #> [107] \"unnecessary_placeholder_linter\" \"unreachable_code_linter\" #> [109] \"unused_import_linter\" \"vector_logic_linter\" #> [111] \"which_grepl_linter\" \"whitespace_linter\" #> [113] \"yoda_test_linter\""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"anyDuplicated() exists replacement (duplicated(.)), efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"any_duplicated_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"Also match usage like length(unique(x$col)) == nrow(x), can replaced anyDuplicated(x$col) == 0L.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_duplicated_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyDuplicated(x) > 0 over any(duplicated(x)) — any_duplicated_linter","text":"","code":"# will produce lints lint( text = \"any(duplicated(x), na.rm = TRUE)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). lint( text = \"length(unique(x)) == length(x)\", linters = any_duplicated_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). # okay lint( text = \"anyDuplicated(x)\", linters = any_duplicated_linter() ) lint( text = \"anyDuplicated(x) == 0L\", linters = any_duplicated_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"anyNA() exists replacement (.na(x)) efficient simple objects, worst equally efficient. Therefore, used situations instead latter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"any_is_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"best_practices, efficiency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/any_is_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of anyNA(x) over any(is.na(x)) — any_is_na_linter","text":"","code":"# will produce lints lint( text = \"any(is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). lint( text = \"any(is.na(foo(x)))\", linters = any_is_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[any_is_na_linter] anyNA(x) is better than any(is.na(x)). # okay lint( text = \"anyNA(x)\", linters = any_is_na_linter() ) lint( text = \"anyNA(foo(x))\", linters = any_is_na_linter() ) lint( text = \"any(!is.na(x), na.rm = TRUE)\", linters = any_is_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Assignment linter — assignment_linter","title":"Assignment linter — assignment_linter","text":"Check <- always used assignment.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assignment linter — assignment_linter","text":"","code":"assignment_linter( allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE, allow_pipe_assign = FALSE )"},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Assignment linter — assignment_linter","text":"allow_cascading_assign Logical, default TRUE. FALSE, <<- ->> allowed. allow_right_assign Logical, default FALSE. TRUE, -> ->> allowed. allow_trailing Logical, default TRUE. FALSE assignments allowed end lines. allow_pipe_assign Logical, default FALSE. TRUE, magrittr's %<>% assignment allowed.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Assignment linter — assignment_linter","text":"configurable, consistency, default, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Assignment linter — assignment_linter","text":"","code":"# will produce lints lint( text = \"x = mean(x)\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not =, for assignment. code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Use <-, not ->, for assignment. #> ::warning file=,line=2,col=3::file=,line=2,col=3,[assignment_linter] Replace ->> by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. lint( text = \"x %<>% as.character()\", linters = assignment_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Avoid the assignment pipe %<>%; prefer using <- and %>% separately. # okay lint( text = \"x <- mean(x)\", linters = assignment_linter() ) code_lines <- \"x <- 1\\ny <<- 2\" writeLines(code_lines) #> x <- 1 #> y <<- 2 lint( text = code_lines, linters = assignment_linter() ) # customizing using arguments code_lines <- \"1 -> x\\n2 ->> y\" writeLines(code_lines) #> 1 -> x #> 2 ->> y lint( text = code_lines, linters = assignment_linter(allow_right_assign = TRUE) ) lint( text = \"x <<- 1\", linters = assignment_linter(allow_cascading_assign = FALSE) ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[assignment_linter] Replace <<- by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior. writeLines(\"foo(bar = \\n 1)\") #> foo(bar = #> 1) lint( text = \"foo(bar = \\n 1)\", linters = assignment_linter(allow_trailing = FALSE) ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[assignment_linter] Assignment = should not be trailing at the end of a line. lint( text = \"x %<>% as.character()\", linters = assignment_linter(allow_pipe_assign = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Linter metadata from a package — available_linters","title":"Get Linter metadata from a package — available_linters","text":"available_linters() obtains tagged list Linters available package. available_tags() searches available tags.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Linter metadata from a package — available_linters","text":"","code":"available_linters(packages = \"lintr\", tags = NULL, exclude_tags = \"deprecated\") available_tags(packages = \"lintr\")"},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Linter metadata from a package — available_linters","text":"packages character vector packages search linters. tags Optional character vector tags search. linters least one matching tag returned. tags NULL, linters returned. See available_tags(\"lintr\") find tags already used lintr. exclude_tags Tags exclude results. Linters least one matching tag returned. exclude_tags NULL, linters excluded. Note tags takes priority, meaning tag found tags exclude_tags included, excluded. Note linters tag \"defunct\" (work can longer run) queried directly. See lintr-deprecated instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get Linter metadata from a package — available_linters","text":"available_linters returns data frame columns 'linter', 'package' 'tags': linter character column naming function associated linter. package character column containing name package providing linter. tags list column containing tags associated linter. available_tags returns character vector linter tags used packages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"package-authors","dir":"Reference","previous_headings":"","what":"Package Authors","title":"Get Linter metadata from a package — available_linters","text":"implement available_linters() package, include file inst/lintr/linters.csv package. CSV file must contain columns 'linter' 'tags', UTF-8 encoded. Additional columns silently ignored present columns identified name. row describes linter function name (e.g. \"assignment_linter\") column 'linter'. space-separated tags associated linter (e.g. \"style consistency default\") column 'tags'. Tags snake_case. See available_tags(\"lintr\") find tags already used lintr.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/available_linters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get Linter metadata from a package — available_linters","text":"","code":"lintr_linters <- available_linters() # If the package doesn't exist or isn't installed, an empty data frame will be returned available_linters(\"does-not-exist\") #> [1] linter package tags #> <0 rows> (or 0-length row.names) lintr_linters2 <- available_linters(c(\"lintr\", \"does-not-exist\")) identical(lintr_linters, lintr_linters2) #> [1] TRUE available_tags() #> [1] \"best_practices\" \"common_mistakes\" \"configurable\" #> [4] \"consistency\" \"correctness\" \"default\" #> [7] \"deprecated\" \"efficiency\" \"executing\" #> [10] \"package_development\" \"pkg_testthat\" \"readability\" #> [13] \"regex\" \"robustness\" \"style\" #> [16] \"tidy_design\""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Backport linter — backport_linter","title":"Backport linter — backport_linter","text":"Check usage unavailable functions. reliable testing r-devel dependencies.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Backport linter — backport_linter","text":"","code":"backport_linter(r_version = getRversion(), except = character())"},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Backport linter — backport_linter","text":"r_version Minimum R version test compatibility except Character vector functions excluded linting. Use list explicitly defined backports, e.g. imported {backports} package manually defined package.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Backport linter — backport_linter","text":"configurable, package_development, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/backport_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Backport linter — backport_linter","text":"","code":"# will produce lints lint( text = \"trimws(x)\", linters = backport_linter(\"3.0.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] trimws (R 3.2.0) is not available for dependency R >= 3.0.0. lint( text = \"str2lang(x)\", linters = backport_linter(\"3.2.0\") ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[backport_linter] str2lang (R 3.6.0) is not available for dependency R >= 3.2.0. # okay lint( text = \"trimws(x)\", linters = backport_linter(\"3.6.0\") ) lint( text = \"str2lang(x)\", linters = backport_linter(\"4.0.0\") )"},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Best practices linters — best_practices_linters","title":"Best practices linters — best_practices_linters","text":"Linters checking use coding best practices, explicit typing numeric constants.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/best_practices_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Best practices linters — best_practices_linters","text":"following linters tagged 'best_practices': absolute_path_linter any_duplicated_linter any_is_na_linter boolean_arithmetic_linter class_equals_linter commented_code_linter condition_call_linter condition_message_linter conjunct_test_linter cyclocomp_linter empty_assignment_linter expect_comparison_linter expect_length_linter expect_named_linter expect_not_linter expect_null_linter expect_s3_class_linter expect_s4_class_linter expect_true_false_linter expect_type_linter fixed_regex_linter for_loop_index_linter function_argument_linter function_return_linter if_switch_linter ifelse_censor_linter implicit_assignment_linter implicit_integer_linter is_numeric_linter length_levels_linter lengths_linter library_call_linter list_comparison_linter literal_coercion_linter nonportable_path_linter nrow_subset_linter nzchar_linter object_overwrite_linter outer_negation_linter paste_linter pipe_return_linter print_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter rep_len_linter routine_registration_linter scalar_in_linter seq_linter sort_linter stopifnot_all_linter system_file_linter T_and_F_symbol_linter terminal_close_linter undesirable_function_linter undesirable_operator_linter unnecessary_lambda_linter unnecessary_nesting_linter unnecessary_placeholder_linter unreachable_code_linter unused_import_linter vector_logic_linter yoda_test_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"length((x == y)) == 0 !(x == y), latter readable efficient.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"boolean_arithmetic_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"best_practices, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/boolean_arithmetic_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of boolean operators over equivalent arithmetic — boolean_arithmetic_linter","text":"","code":"# will produce lints lint( text = \"length(which(x == y)) == 0L\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). lint( text = \"sum(grepl(pattern, x)) == 0\", linters = boolean_arithmetic_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[boolean_arithmetic_linter] Use any() to express logical aggregations. For example, replace length(which(x == y)) == 0 with !any(x == y). # okay lint( text = \"!any(x == y)\", linters = boolean_arithmetic_linter() ) lint( text = \"!any(grepl(pattern, x))\", linters = boolean_arithmetic_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Brace linter — brace_linter","title":"Brace linter — brace_linter","text":"Perform various style checks related placement spacing curly braces:","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Brace linter — brace_linter","text":"","code":"brace_linter(allow_single_line = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Brace linter — brace_linter","text":"allow_single_line TRUE, allow open closed curly pair line.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Brace linter — brace_linter","text":"Opening curly braces never line always followed newline. Opening curly braces space . Closing curly braces line unless followed else. Closing curly braces conditions line corresponding else. Either neither branch /else use curly braces, .e., either branches use {...} neither . Functions spanning multiple lines use curly braces.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Brace linter — brace_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/brace_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Brace linter — brace_linter","text":"","code":"# will produce lints lint( text = \"f <- function() { 1 }\", linters = brace_linter() ) #> ::warning file=,line=1,col=17::file=,line=1,col=17,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line. #> ::warning file=,line=1,col=21::file=,line=1,col=21,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. writeLines(\"if (TRUE) {\\n return(1) }\") #> if (TRUE) { #> return(1) } lint( text = \"if (TRUE) {\\n return(1) }\", linters = brace_linter() ) #> ::warning file=,line=2,col=12::file=,line=2,col=12,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else. # okay writeLines(\"f <- function() {\\n 1\\n}\") #> f <- function() { #> 1 #> } lint( text = \"f <- function() {\\n 1\\n}\", linters = brace_linter() ) writeLines(\"if (TRUE) { \\n return(1) \\n}\") #> if (TRUE) { #> return(1) #> } lint( text = \"if (TRUE) { \\n return(1) \\n}\", linters = brace_linter() ) # customizing using arguments writeLines(\"if (TRUE) { return(1) }\") #> if (TRUE) { return(1) } lint( text = \"if (TRUE) { return(1) }\", linters = brace_linter(allow_single_line = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Checkstyle Report for lint results — checkstyle_output","title":"Checkstyle Report for lint results — checkstyle_output","text":"Generate report linting results using Checkstyle XML format.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Checkstyle Report for lint results — checkstyle_output","text":"","code":"checkstyle_output(lints, filename = \"lintr_results.xml\")"},{"path":"https://lintr.r-lib.org/dev/reference/checkstyle_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Checkstyle Report for lint results — checkstyle_output","text":"lints linting results. filename name output report","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block comparison of class with == — class_equals_linter","title":"Block comparison of class with == — class_equals_linter","text":"Usage like class(x) == \"character\" prone error since class R general vector. correct version S3 classes inherits(): inherits(x, \"character\"). Often, class k . equivalent, example .character() .data.frame().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block comparison of class with == — class_equals_linter","text":"","code":"class_equals_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Block comparison of class with == — class_equals_linter","text":"Similar reasoning applies class(x) %% \"character\".","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block comparison of class with == — class_equals_linter","text":"best_practices, consistency, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/class_equals_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block comparison of class with == — class_equals_linter","text":"","code":"# will produce lints lint( text = 'is_lm <- class(x) == \"lm\"', linters = class_equals_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with ==. lint( text = 'if (\"lm\" %in% class(x)) is_lm <- TRUE', linters = class_equals_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[class_equals_linter] Use inherits(x, 'class-name'), is. or is(x, 'class') instead of comparing class(x) with %in%. # okay lint( text = 'is_lm <- inherits(x, \"lm\")', linters = class_equals_linter() ) lint( text = 'if (inherits(x, \"lm\")) is_lm <- TRUE', linters = class_equals_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":null,"dir":"Reference","previous_headings":"","what":"Clear the lintr cache — clear_cache","title":"Clear the lintr cache — clear_cache","text":"Clear lintr cache","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Clear the lintr cache — clear_cache","text":"","code":"clear_cache(file = NULL, path = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Clear the lintr cache — clear_cache","text":"file filename whose cache clear. pass NULL, delete caches. path directory store caches. Reads option 'lintr.cache_directory' default.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/clear_cache.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Clear the lintr cache — clear_cache","text":"0 success, 1 failure, invisibly.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commas linter — commas_linter","title":"Commas linter — commas_linter","text":"Check commas followed spaces, spaces .","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commas linter — commas_linter","text":"","code":"commas_linter(allow_trailing = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Commas linter — commas_linter","text":"allow_trailing TRUE, linter allows comma followed directly closing bracket without space.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commas linter — commas_linter","text":"configurable, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commas_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commas linter — commas_linter","text":"","code":"# will produce lints lint( text = \"switch(op , x = foo, y = bar)\", linters = commas_linter() ) #> ::warning file=,line=1,col=10::file=,line=1,col=10,[commas_linter] Remove spaces before a comma. lint( text = \"mean(x,trim = 0.2,na.rm = TRUE)\", linters = commas_linter() ) #> ::warning file=,line=1,col=8::file=,line=1,col=8,[commas_linter] Put a space after a comma. #> ::warning file=,line=1,col=19::file=,line=1,col=19,[commas_linter] Put a space after a comma. lint( text = \"x[ ,, drop=TRUE]\", linters = commas_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commas_linter] Remove spaces before a comma. #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Put a space after a comma. lint( text = \"x[1,]\", linters = commas_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[commas_linter] Put a space after a comma. # okay lint( text = \"switch(op, x = foo, y = bar)\", linters = commas_linter() ) lint( text = \"switch(op, x = , y = bar)\", linters = commas_linter() ) lint( text = \"mean(x, trim = 0.2, na.rm = TRUE)\", linters = commas_linter() ) lint( text = \"a[1, , 2, , 3]\", linters = commas_linter() ) lint( text = \"x[1,]\", linters = commas_linter(allow_trailing = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Commented code linter — commented_code_linter","title":"Commented code linter — commented_code_linter","text":"Check commented code outside roxygen blocks.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Commented code linter — commented_code_linter","text":"","code":"commented_code_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Commented code linter — commented_code_linter","text":"best_practices, default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/commented_code_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Commented code linter — commented_code_linter","text":"","code":"# will produce lints lint( text = \"# x <- 1\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=3::file=,line=1,col=3,[commented_code_linter] Remove commented code. lint( text = \"x <- f() # g()\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[commented_code_linter] Remove commented code. lint( text = \"x + y # + z[1, 2]\", linters = commented_code_linter() ) #> ::warning file=,line=1,col=9::file=,line=1,col=9,[commented_code_linter] Remove commented code. # okay lint( text = \"x <- 1; x <- f(); x + y\", linters = commented_code_linter() ) lint( text = \"#' x <- 1\", linters = commented_code_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Common mistake linters — common_mistakes_linters","title":"Common mistake linters — common_mistakes_linters","text":"Linters highlighting common mistakes, duplicate arguments.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/common_mistakes_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Common mistake linters — common_mistakes_linters","text":"following linters tagged 'common_mistakes': duplicate_argument_linter equals_na_linter length_test_linter list_comparison_linter missing_argument_linter missing_package_linter pipe_return_linter redundant_equals_linter sprintf_linter unused_import_linter vector_logic_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"!(x == y) readably expressed x != y. true negations simple comparisons like !(x > y) !(x <= y).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"","code":"comparison_negation_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"consistency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/comparison_negation_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usages like !(x == y) where a direct relational operator is appropriate — comparison_negation_linter","text":"","code":"# will produce lints lint( text = \"!x == 2\", linters = comparison_negation_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[comparison_negation_linter] Use x != y, not !(x == y). lint( text = \"!(x > 2)\", linters = comparison_negation_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[comparison_negation_linter] Use x <= y, not !(x > y). # okay lint( text = \"!(x == 2 & y > 2)\", linters = comparison_negation_linter() ) lint( text = \"!(x & y)\", linters = comparison_negation_linter() ) lint( text = \"x != 2\", linters = comparison_negation_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Recommend usage of call. = FALSE in conditions — condition_call_linter","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"linter, default display_call = FALSE, enforces recommendation tidyverse design guide regarding displaying error calls.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"","code":"condition_call_linter(display_call = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"display_call Logical specifying expected behavior regarding call. argument conditions. NA forces providing call. = ignores value (can used cases expect mix call. = FALSE call. = TRUE) TRUE lints call. = FALSE FALSE forces call. = FALSE (lints call. = TRUE missing call. = value)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"best_practices, configurable, style, tidy_design","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_call_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Recommend usage of call. = FALSE in conditions — condition_call_linter","text":"","code":"# will produce lints lint( text = \"stop('test')\", linters = condition_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. lint( text = \"stop('test', call. = TRUE)\", linters = condition_call_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message. lint( text = \"stop('test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(.) to display the call in an error message. lint( text = \"stop('this is a', 'test', call. = FALSE)\", linters = condition_call_linter(display_call = TRUE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_call_linter] Use stop(.) to display the call in an error message. # okay lint( text = \"stop('test', call. = FALSE)\", linters = condition_call_linter() ) lint( text = \"stop('this is a', 'test', call. = FALSE)\", linters = condition_call_linter() ) lint( text = \"stop('test', call. = TRUE)\", linters = condition_call_linter(display_call = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"linter discourages combining condition functions like stop() string concatenation functions paste() paste0(). stop(paste0(...)) redundant exactly equivalent stop(...) stop(paste(...)) similarly equivalent stop(...) separators (see examples) applies default condition functions well, .e., warning(), message(), packageStartupMessage().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"condition_message_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"best_practices, consistency","code":""},{"path":"https://lintr.r-lib.org/dev/reference/condition_message_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of paste() and paste0() with messaging functions using ... — condition_message_linter","text":"","code":"# will produce lints lint( text = 'stop(paste(\"a string\", \"another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste to build stop strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). lint( text = 'warning(paste0(\"a string\", \" another\"))', linters = condition_message_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[condition_message_linter] Don't use paste0 to build warning strings. Instead use the fact that these functions build condition message strings from their input (using \"\" as a separator). For translatable strings, prefer using gettextf(). # okay lint( text = 'stop(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(\"a string\", \" another\")', linters = condition_message_linter() ) lint( text = 'warning(paste(\"a string\", \"another\", sep = \"-\"))', linters = condition_message_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Configurable linters — configurable_linters","title":"Configurable linters — configurable_linters","text":"Generic linters support custom configuration needs.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/configurable_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Configurable linters — configurable_linters","text":"following linters tagged 'configurable': absolute_path_linter assignment_linter backport_linter brace_linter commas_linter condition_call_linter conjunct_test_linter consecutive_mutate_linter cyclocomp_linter duplicate_argument_linter fixed_regex_linter if_not_else_linter if_switch_linter implicit_assignment_linter implicit_integer_linter indentation_linter infix_spaces_linter library_call_linter line_length_linter missing_argument_linter namespace_linter nested_pipe_linter nonportable_path_linter object_length_linter object_name_linter object_overwrite_linter object_usage_linter paste_linter pipe_consistency_linter quotes_linter redundant_ifelse_linter return_linter semicolon_linter string_boundary_linter todo_comment_linter trailing_whitespace_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unnecessary_lambda_linter unnecessary_nesting_linter unreachable_code_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force && conditions to be written separately where appropriate — conjunct_test_linter","title":"Force && conditions to be written separately where appropriate — conjunct_test_linter","text":"readability test outputs, testing one thing per call testthat::expect_true() preferable, .e., expect_true(); expect_true(B) better expect_true(&& B), expect_false(); expect_false(B) better expect_false(|| B).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force && conditions to be written separately where appropriate — conjunct_test_linter","text":"","code":"conjunct_test_linter( allow_named_stopifnot = TRUE, allow_filter = c(\"never\", \"not_dplyr\", \"always\") )"},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Force && conditions to be written separately where appropriate — conjunct_test_linter","text":"allow_named_stopifnot Logical, TRUE default. FALSE, \"named\" calls stopifnot(), available since R 4.0.0 provide helpful messages test failures, also linted. allow_filter Character naming method linting calls filter(). default, \"never\", means filter() dplyr::filter() calls linted; \"not_dplyr\" means dplyr::filter() calls linted; \"always\" means calls filter() linted. Calls like stats::filter() never linted.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Force && conditions to be written separately where appropriate — conjunct_test_linter","text":"Similar reasoning applies && usage inside stopifnot() assertthat::assert_that() calls. Relatedly, dplyr::filter(DF, & B) dplyr::filter(DF, , B), latter readable / easier format long conditions. Note linter assumes usages filter() dplyr::filter(); using another function named filter(), e.g. stats::filter(), please namespace-qualify avoid false positives. can omit linting filter() expressions altogether via allow_filter = TRUE.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force && conditions to be written separately where appropriate — conjunct_test_linter","text":"best_practices, configurable, package_development, pkg_testthat, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/conjunct_test_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force && conditions to be written separately where appropriate — conjunct_test_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x && y)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Write multiple expectations like expect_true(A) and expect_true(B) instead of expect_true(A && B). The latter will produce better error messages in the case of failure. lint( text = \"expect_false(x || (y && z))\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Write multiple expectations like expect_false(A) and expect_false(B) instead of expect_false(A || B). The latter will produce better error messages in the case of failure. lint( text = \"stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))\", linters = conjunct_test_linter(allow_named_stopifnot = FALSE) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[conjunct_test_linter] Write multiple conditions like stopifnot(A, B) instead of stopifnot(A && B). The latter will produce better error messages in the case of failure. lint( text = \"dplyr::filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=23::file=,line=1,col=23,[conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). lint( text = \"filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter() ) #> ::warning file=,line=1,col=16::file=,line=1,col=16,[conjunct_test_linter] Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B). # okay lint( text = \"expect_true(x || (y && z))\", linters = conjunct_test_linter() ) lint( text = 'stopifnot(\"x must be a logical scalar\" = length(x) == 1 && is.logical(x) && !is.na(x))', linters = conjunct_test_linter(allow_named_stopifnot = TRUE) ) lint( text = \"dplyr::filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter(allow_filter = \"always\") ) lint( text = \"filter(mtcars, mpg > 20 & vs == 0)\", linters = conjunct_test_linter(allow_filter = \"not_dplyr\") ) lint( text = \"stats::filter(mtcars$cyl, mtcars$mpg > 20 & mtcars$vs == 0)\", linters = conjunct_test_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"stopifnot() accepts number tests, sequences like stopifnot(x); stopifnot(y) redundant. Ditto tests using assertthat::assert_that() without specifying msg=.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"consecutive_assertion_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"consistency, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_assertion_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Force consecutive calls to assertions into just one when possible — consecutive_assertion_linter","text":"","code":"# will produce lints lint( text = \"stopifnot(x); stopifnot(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to stopifnot(). lint( text = \"assert_that(x); assert_that(y)\", linters = consecutive_assertion_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to assert_that(). # okay lint( text = \"stopifnot(x, y)\", linters = consecutive_assertion_linter() ) lint( text = 'assert_that(x, msg = \"Bad x!\"); assert_that(y)', linters = consecutive_assertion_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"dplyr::mutate() accepts number columns, sequences like DF %>% dplyr::mutate(..1) %>% dplyr::mutate(..2) redundant -- can always expressed single call dplyr::mutate().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"","code":"consecutive_mutate_linter(invalid_backends = \"dbplyr\")"},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"invalid_backends Character vector packages providing dplyr backends may compatible combining mutate() calls cases. Defaults \"dbplyr\" since SQL backends can handle re-using variable defined mutate() expression.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"exception SQL back-ends, translation logic may sophisticated default dplyr, example DF %>% mutate(= + 1) %>% mutate(b = - 2).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"configurable, consistency, efficiency, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/consecutive_mutate_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require consecutive calls to mutate() to be combined when possible — consecutive_mutate_linter","text":"","code":"# will produce lints lint( text = \"x %>% mutate(a = 1) %>% mutate(b = 2)\", linters = consecutive_mutate_linter() ) #> ::warning file=,line=1,col=25::file=,line=1,col=25,[consecutive_mutate_linter] Unify consecutive calls to mutate(). # okay lint( text = \"x %>% mutate(a = 1, b = 2)\", linters = consecutive_mutate_linter() ) code <- \"library(dbplyr)\\nx %>% mutate(a = 1) %>% mutate(a = a + 1)\" writeLines(code) #> library(dbplyr) #> x %>% mutate(a = 1) %>% mutate(a = a + 1) lint( text = code, linters = consecutive_mutate_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Consistency linters — consistency_linters","title":"Consistency linters — consistency_linters","text":"Linters checking enforcing consistent alternative multiple syntactically valid ways write something.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/consistency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Consistency linters — consistency_linters","text":"following linters tagged 'consistency': assignment_linter class_equals_linter comparison_negation_linter condition_message_linter consecutive_assertion_linter consecutive_mutate_linter function_argument_linter if_not_else_linter if_switch_linter implicit_integer_linter inner_combine_linter is_numeric_linter keyword_quote_linter length_levels_linter literal_coercion_linter nested_pipe_linter nrow_subset_linter numeric_leading_zero_linter nzchar_linter object_name_linter paste_linter print_linter quotes_linter redundant_ifelse_linter rep_len_linter scalar_in_linter seq_linter system_file_linter T_and_F_symbol_linter unnecessary_nesting_linter which_grepl_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Correctness linters — correctness_linters","title":"Correctness linters — correctness_linters","text":"Linters highlighting possible programming mistakes, unused variables.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/correctness_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Correctness linters — correctness_linters","text":"following linters tagged 'correctness': duplicate_argument_linter equals_na_linter missing_argument_linter namespace_linter object_usage_linter package_hooks_linter sprintf_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Cyclomatic complexity linter — cyclocomp_linter","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"Check overly complicated expressions. See cyclocomp() function {cyclocomp}.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"cyclocomp_linter(complexity_limit = 15L)"},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"complexity_limit Maximum cyclomatic complexity, default 15. Expressions complex linted.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"best_practices, configurable, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/cyclocomp_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cyclomatic complexity linter — cyclocomp_linter","text":"","code":"# will produce lints lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 1L) ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 2 to at most 1. # okay lint( text = \"if (TRUE) 1 else 2\", linters = cyclocomp_linter(complexity_limit = 2L) )"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Default linters — default_linters","title":"Default linters — default_linters","text":"List default linters lint(). Use linters_with_defaults() customize . default linters based tidyverse style guide. set default linters follows (parameterized linters, e.g., line_length_linter use default argument(s), see ? details):","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default linters — default_linters","text":"","code":"default_linters"},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default linters — default_linters","text":"object class list length 25.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Default linters — default_linters","text":"following linters tagged 'default': assignment_linter brace_linter commas_linter commented_code_linter equals_na_linter function_left_parentheses_linter indentation_linter infix_spaces_linter line_length_linter object_length_linter object_name_linter object_usage_linter paren_body_linter pipe_continuation_linter quotes_linter return_linter semicolon_linter seq_linter spaces_inside_linter spaces_left_parentheses_linter T_and_F_symbol_linter trailing_blank_lines_linter trailing_whitespace_linter vector_logic_linter whitespace_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":null,"dir":"Reference","previous_headings":"","what":"Default lintr settings — default_settings","title":"Default lintr settings — default_settings","text":"default settings consist linters: list default linters (see default_linters()) encoding: character encoding assumed file exclude: pattern used exclude line code exclude_start, exclude_end: patterns used mark start end code block exclude exclude_linter, exclude_linter_sep: patterns used exclude linters exclusions: list exclusions, see exclude() complete description valid values. cache_directory: location cache directory comment_token: GitHub token character error_on_lint: decides error produced lints found settings without defaults, .e., list describes every valid setting.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default lintr settings — default_settings","text":"","code":"default_settings"},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default lintr settings — default_settings","text":"object class list length 12.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/default_settings.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Default lintr settings — default_settings","text":"","code":"# available settings names(default_settings) #> [1] \"linters\" \"encoding\" \"exclude\" #> [4] \"exclude_next\" \"exclude_start\" \"exclude_end\" #> [7] \"exclude_linter\" \"exclude_linter_sep\" \"exclusions\" #> [10] \"cache_directory\" \"comment_token\" \"error_on_lint\" # linters included by default names(default_settings$linters) #> [1] \"assignment_linter\" \"brace_linter\" #> [3] \"commas_linter\" \"commented_code_linter\" #> [5] \"equals_na_linter\" \"function_left_parentheses_linter\" #> [7] \"indentation_linter\" \"infix_spaces_linter\" #> [9] \"line_length_linter\" \"object_length_linter\" #> [11] \"object_name_linter\" \"object_usage_linter\" #> [13] \"paren_body_linter\" \"pipe_continuation_linter\" #> [15] \"quotes_linter\" \"return_linter\" #> [17] \"semicolon_linter\" \"seq_linter\" #> [19] \"spaces_inside_linter\" \"spaces_left_parentheses_linter\" #> [21] \"T_and_F_symbol_linter\" \"trailing_blank_lines_linter\" #> [23] \"trailing_whitespace_linter\" \"vector_logic_linter\" #> [25] \"whitespace_linter\" # default values for a few of the other settings default_settings[c( \"encoding\", \"exclude\", \"exclude_start\", \"exclude_end\", \"exclude_linter\", \"exclude_linter_sep\", \"exclusions\", \"error_on_lint\" )] #> $encoding #> [1] \"UTF-8\" #> #> $exclude #> #[[:space:]]*nolint #> #> $exclude_start #> #[[:space:]]*nolint start #> #> $exclude_end #> #[[:space:]]*nolint end #> #> $exclude_linter #> ^[[:space:]]*:[[:space:]]*(?(?:(?:[^,.])+[[:space:]]*,[[:space:]]*)*(?:[^,.])+)\\. #> #> $exclude_linter_sep #> [[:space:]]*,[[:space:]]* #> #> $exclusions #> list() #> #> $error_on_lint #> [1] FALSE #>"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":null,"dir":"Reference","previous_headings":"","what":"Default undesirable functions and operators — all_undesirable_functions","title":"Default undesirable functions and operators — all_undesirable_functions","text":"Lists function names operators undesirable_function_linter() undesirable_operator_linter(). list default elements another contains available elements. Use modify_defaults() produce custom list.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default undesirable functions and operators — all_undesirable_functions","text":"","code":"all_undesirable_functions default_undesirable_functions all_undesirable_operators default_undesirable_operators"},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Default undesirable functions and operators — all_undesirable_functions","text":"named list character strings.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/default_undesirable_functions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Default undesirable functions and operators — all_undesirable_functions","text":"following functions sometimes regarded undesirable: .libPaths() alternative, use withr::with_libpaths() temporary change instead permanently modifying library location. attach() alternative, use roxygen2's @importFrom statement packages, :: scripts. attach() modifies global search path. browser() alternative, remove likely leftover debugging. pauses execution run. debug() alternative, remove likely leftover debugging. traps function causes execution pause function run. debugcall() alternative, remove likely leftover debugging. traps function causes execution pause function run. debugonce() alternative, remove likely leftover debugging. traps function causes execution pause function run. detach() alternative, avoid modifying global search path. Detaching environments search path rarely necessary production code. library() alternative, use roxygen2's @importFrom statement packages :: scripts, instead modifying global search path. mapply() alternative, use Map() guarantee list returned simplify accordingly. options() alternative, use withr::with_options() temporary change instead permanently modifying session options. par() alternative, use withr::with_par() temporary change instead permanently modifying graphics device parameters. require() alternative, use roxygen2's @importFrom statement packages library() :: scripts, instead modifying global search path. sapply() alternative, use vapply() appropriate FUN.VALUE= argument obtain type-stable simplification. setwd() alternative, use withr::with_dir() temporary change instead modifying global working directory. sink() alternative, use withr::with_sink() temporary redirection instead permanently redirecting output. source() alternative, manage dependencies packages. source() loads code global environment unless local = TRUE used, can cause hard--predict behavior. structure() alternative, Use class<-, names<-, attr<- set attributes. Sys.setenv() alternative, use withr::with_envvar() temporary change instead permanently modifying global environment variables. Sys.setlocale() alternative, use withr::with_locale() temporary change instead permanently modifying session locale. trace() alternative, remove likely leftover debugging. traps function causes execution arbitrary code function run. undebug() alternative, remove likely leftover debugging. useful interactive debugging debug(). untrace() alternative, remove likely leftover debugging. useful interactive debugging trace(). following operators sometimes regarded undesirable: <<-. assigns outside current environment way can hard reason . Prefer fully-encapsulated functions wherever possible, , necessary, assign specific environment assign(). Recall can create environment desired scope new.env(). :::. accesses non-exported functions inside packages. Code relying likely break future versions package functions part public interface may changed removed maintainers without notice. Use public functions via :: instead. <<-. assigns outside current environment way can hard reason . Prefer fully-encapsulated functions wherever possible, , necessary, assign specific environment assign(). Recall can create environment desired scope new.env().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated linters — deprecated_linters","title":"Deprecated linters — deprecated_linters","text":"Linters deprecated provided backwards compatibility . linters excluded linters_with_tags() default.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/deprecated_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Deprecated linters — deprecated_linters","text":"following linters tagged 'deprecated': consecutive_stopifnot_linter extraction_operator_linter no_tab_linter single_quotes_linter unnecessary_nested_if_linter unneeded_concatenation_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Duplicate argument linter — duplicate_argument_linter","title":"Duplicate argument linter — duplicate_argument_linter","text":"Check duplicate arguments function calls. cases run-time errors (e.g. mean(x = 1:5, x = 2:3)), otherwise linter used discourage explicitly providing duplicate names objects (e.g. c(= 1, = 2)). Duplicate-named objects hard work programmatically typically avoided.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"duplicate_argument_linter(except = c(\"mutate\", \"transmute\"))"},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Duplicate argument linter — duplicate_argument_linter","text":"except character vector function names exceptions. Defaults functions allow sequential updates variables, currently dplyr::mutate() dplyr::transmute().","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Duplicate argument linter — duplicate_argument_linter","text":"common_mistakes, configurable, correctness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/duplicate_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Duplicate argument linter — duplicate_argument_linter","text":"","code":"# will produce lints lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=13::file=,line=1,col=13,[duplicate_argument_linter] Avoid duplicate arguments in function calls. lint( text = \"fun(arg = 1, arg = 2)\", linters = duplicate_argument_linter() ) #> ::warning file=,line=1,col=14::file=,line=1,col=14,[duplicate_argument_linter] Avoid duplicate arguments in function calls. # okay lint( text = \"list(x = 1, x = 2)\", linters = duplicate_argument_linter(except = \"list\") ) lint( text = \"df %>% dplyr::mutate(x = a + b, x = x + d)\", linters = duplicate_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Efficiency linters — efficiency_linters","title":"Efficiency linters — efficiency_linters","text":"Linters highlighting code efficiency problems, unnecessary function calls.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/efficiency_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Efficiency linters — efficiency_linters","text":"following linters tagged 'efficiency': any_duplicated_linter any_is_na_linter boolean_arithmetic_linter consecutive_mutate_linter fixed_regex_linter if_switch_linter ifelse_censor_linter inner_combine_linter length_test_linter lengths_linter list_comparison_linter literal_coercion_linter matrix_apply_linter nested_ifelse_linter nrow_subset_linter nzchar_linter outer_negation_linter redundant_equals_linter redundant_ifelse_linter regex_subset_linter routine_registration_linter sample_int_linter scalar_in_linter seq_linter sort_linter string_boundary_linter undesirable_function_linter undesirable_operator_linter unnecessary_concatenation_linter unnecessary_lambda_linter vector_logic_linter which_grepl_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block assignment of {} — empty_assignment_linter","title":"Block assignment of {} — empty_assignment_linter","text":"Assignment {} assignment NULL; use latter clarity. Closely related: unnecessary_concatenation_linter().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"empty_assignment_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block assignment of {} — empty_assignment_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/empty_assignment_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block assignment of {} — empty_assignment_linter","text":"","code":"# will produce lints lint( text = \"x <- {}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. writeLines(\"x = {\\n}\") #> x = { #> } lint( text = \"x = {\\n}\", linters = empty_assignment_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[empty_assignment_linter] Assign NULL explicitly or, whenever possible, allocate the empty object with the right type and size. # okay lint( text = \"x <- { 3 + 4 }\", linters = empty_assignment_linter() ) lint( text = \"x <- NULL\", linters = empty_assignment_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality check with NA linter — equals_na_linter","title":"Equality check with NA linter — equals_na_linter","text":"Check x == NA, x != NA x %% NA. usage almost surely incorrect -- checks missing values done .na().","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality check with NA linter — equals_na_linter","text":"","code":"equals_na_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Equality check with NA linter — equals_na_linter","text":"common_mistakes, correctness, default, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/equals_na_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality check with NA linter — equals_na_linter","text":"","code":"# will produce lints lint( text = \"x == NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of x == NA lint( text = \"x != NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of x != NA lint( text = \"x %in% NA\", linters = equals_na_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[equals_na_linter] Use is.na() instead of x %in% NA # okay lint( text = \"is.na(x)\", linters = equals_na_linter() ) lint( text = \"!is.na(x)\", linters = equals_na_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":null,"dir":"Reference","previous_headings":"","what":"Exclude lines or files from linting — exclude","title":"Exclude lines or files from linting — exclude","text":"Exclude lines files linting","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Exclude lines or files from linting — exclude","text":"","code":"exclude(lints, exclusions = settings$exclusions, linter_names = NULL, ...)"},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Exclude lines or files from linting — exclude","text":"lints need filtered. exclusions manually specified exclusions linter_names character vector names active linters, used parsing inline exclusions. ... additional arguments passed parse_exclusions()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/exclude.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Exclude lines or files from linting — exclude","text":"Exclusions can specified three different ways. Single line source file. default: # nolint, possibly followed listing linters exclude. listing missing, linters excluded line. default listing format # nolint: linter_name, linter2_name.. may anything colon line exclusion tag listing must terminated full stop (.) linter list respected. Line range source file. default: # nolint start, # nolint end. # nolint start accepts linter lists form # nolint. Exclusions parameter, list named /unnamed entries. Outer elements following characteristics: Unnamed elements specify filenames directories. Named elements vector list line numbers, Inf indicating 'lines'. name gives path relative config. Unnamed elements denote exclusion linters given path directory. Named elements, name specifies linter, denote exclusion linter. convenience, vector can used place list whenever introduce ambiguity, e.g. character vector files exclude vector lines exclude.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":null,"dir":"Reference","previous_headings":"","what":"Code executing linters — executing_linters","title":"Code executing linters — executing_linters","text":"Linters evaluate parts linted code, loading referenced packages. linters used untrusted code, may need dependencies linted package project available order function correctly. package authors, note includes loading package , e.g. pkgload::load_all() installing attaching package.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/executing_linters.html","id":"linters","dir":"Reference","previous_headings":"","what":"Linters","title":"Code executing linters — executing_linters","text":"following linters tagged 'executing': namespace_linter object_length_linter object_name_linter object_overwrite_linter object_usage_linter unused_import_linter","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"testthat::expect_gt(), testthat::expect_gte(), testthat::expect_lt(), testthat::expect_lte(), testthat::expect_equal() exist specifically testing comparisons two objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"expect_comparison_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"best_practices, package_development, pkg_testthat","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_comparison_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_gt(x, y) over expect_true(x > y) (and similar) — expect_comparison_linter","text":"","code":"# will produce lints lint( text = \"expect_true(x > y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y). lint( text = \"expect_true(x <= y)\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y). lint( text = \"expect_true(x == (y == 2))\", linters = expect_comparison_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y). # okay lint( text = \"expect_gt(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_lte(x, y)\", linters = expect_comparison_linter() ) lint( text = \"expect_identical(x, y == 2)\", linters = expect_comparison_linter() ) lint( text = \"expect_true(x < y | x > y^2)\", linters = expect_comparison_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter enforces usage testthat::expect_identical() default expectation comparisons testthat suite. expect_true(identical(x, y)) equivalent unadvised method test. , testthat::expect_equal() used expect_identical() inappropriate, .e., x y need numerically equivalent instead fully identical (case, provide tolerance= argument expect_equal() explicitly). also applies inconvenient check full equality (e.g., names can ignored, case ignore_attr = \"names\" supplied expect_equal() (, 2nd edition, check.attributes = FALSE).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"expect_identical_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"exceptions","dir":"Reference","previous_headings":"","what":"Exceptions","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"linter allows expect_equal() three circumstances: named argument set (e.g. ignore_attr tolerance) Comparison made explicit decimal, e.g. expect_equal(x, 1.0) (implicitly setting tolerance) ... passed (wrapper functions might set arguments ignore_attr tolerance)","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"package_development, pkg_testthat","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_identical_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_identical(x, y) where appropriate — expect_identical_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, y)\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. lint( text = \"expect_true(identical(x, y))\", linters = expect_identical_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=. # okay lint( text = \"expect_identical(x, y)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, check.attributes = FALSE)\", linters = expect_identical_linter() ) lint( text = \"expect_equal(x, y, tolerance = 1e-6)\", linters = expect_identical_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"testthat::expect_length() exists specifically testing length() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"expect_length_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"best_practices, package_development, pkg_testthat, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_length_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_length(x, n) over expect_equal(length(x), n) — expect_length_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(length(x), 2L)\", linters = expect_length_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n) # okay lint( text = \"expect_length(x, 2L)\", linters = expect_length_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint expectation — expect_lint","title":"Lint expectation — expect_lint","text":"expectation 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\", \"trailing blank\", trailing_blank_lines_linter()) expect_lint(\"a\\n\", list(message = \"trailing blank\", line_number = 2), trailing_blank_lines_linter()) # several expected lints expect_lint(\"a\\n\\n\", list(\"trailing blank\", \"trailing blank\"), trailing_blank_lines_linter()) expect_lint( \"a\\n\\n\", list( list(message = \"trailing blank\", line_number = 2), list(message = \"trailing blank\", line_number = 3) ), trailing_blank_lines_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":null,"dir":"Reference","previous_headings":"","what":"Test that the package is lint free — expect_lint_free","title":"Test that the package is lint free — expect_lint_free","text":"function thin wrapper around lint_package simply tests lints package. can used ensure tests fail package contains lints.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test that the package is lint free — expect_lint_free","text":"","code":"expect_lint_free(...)"},{"path":"https://lintr.r-lib.org/dev/reference/expect_lint_free.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test that the package is lint free — expect_lint_free","text":"... arguments passed lint_package()","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"testthat::expect_named() exists specifically testing names() object. testthat::expect_equal() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"expect_named_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"best_practices, package_development, pkg_testthat, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_named_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_named(x, n) over expect_equal(names(x), n) — expect_named_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(names(x), \"a\")', linters = expect_named_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n) # okay lint( text = 'expect_named(x, \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(colnames(x), \"a\")', linters = expect_named_linter() ) lint( text = 'expect_equal(dimnames(x), \"a\")', linters = expect_named_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"testthat::expect_false() exists specifically testing output FALSE. testthat::expect_true() can also used tests negating output, better use tailored function instead. reverse also true -- use expect_false() instead expect_true(!).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"expect_not_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"best_practices, package_development, pkg_testthat, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_not_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_false(x) over expect_true(!x) — expect_not_linter","text":"","code":"# will produce lints lint( text = \"expect_true(!x)\", linters = expect_not_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa. # okay lint( text = \"expect_false(x)\", linters = expect_not_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_null for checking NULL — expect_null_linter","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"Require usage expect_null(x) expect_equal(x, NULL) similar usages.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"expect_null_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"testthat::expect_null() exists specifically testing NULL objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"best_practices, package_development, pkg_testthat","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_null_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_null for checking NULL — expect_null_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_equal(x, NULL) lint( text = \"expect_identical(x, NULL)\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_identical(x, NULL) lint( text = \"expect_true(is.null(x))\", linters = expect_null_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_true(is.null(x)) # okay lint( text = \"expect_null(x)\", linters = expect_null_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s3_class() — expect_s3_class_linter","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"testthat::expect_s3_class() exists specifically testing class S3 objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"expect_s3_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"best_practices, package_development, pkg_testthat","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s3_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s3_class() — expect_s3_class_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(class(x), \"data.frame\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. lint( text = 'expect_equal(class(x), \"numeric\")', linters = expect_s3_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s3_class_linter] expect_s3_class(x, k) is better than expect_equal(class(x), k). Note also expect_s4_class() available for testing S4 objects. # okay lint( text = 'expect_s3_class(x, \"data.frame\")', linters = expect_s3_class_linter() ) lint( text = 'expect_type(x, \"double\")', linters = expect_s3_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"testthat::expect_s4_class() exists specifically testing class S4 objects. testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"expect_s4_class_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"best_practices, package_development, pkg_testthat","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_s4_class_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_s4_class(x, k) over expect_true(is(x, k)) — expect_s4_class_linter","text":"","code":"# will produce lints lint( text = 'expect_true(is(x, \"Matrix\"))', linters = expect_s4_class_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_s4_class_linter] expect_s4_class(x, k) is better than expect_true(is(x, k)). Note also expect_s3_class() available for testing S3 objects. # okay lint( text = 'expect_s4_class(x, \"Matrix\")', linters = expect_s4_class_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"testthat::expect_true() testthat::expect_false() exist specifically testing TRUE/FALSE value object. testthat::expect_equal() testthat::expect_identical() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"expect_true_false_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"best_practices, package_development, pkg_testthat, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_true_false_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_true(x) over expect_equal(x, TRUE) — expect_true_false_linter","text":"","code":"# will produce lints lint( text = \"expect_equal(x, TRUE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE) lint( text = \"expect_equal(x, FALSE)\", linters = expect_true_false_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE) # okay lint( text = \"expect_true(x)\", linters = expect_true_false_linter() ) lint( text = \"expect_false(x)\", linters = expect_true_false_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"testthat::expect_type() exists specifically testing storage type objects. testthat::expect_equal(), testthat::expect_identical(), testthat::expect_true() can also used tests, better use tailored function instead.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"expect_type_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"best_practices, package_development, pkg_testthat","code":""},{"path":"https://lintr.r-lib.org/dev/reference/expect_type_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of expect_type(x, type) over expect_equal(typeof(x), type) — expect_type_linter","text":"","code":"# will produce lints lint( text = 'expect_equal(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t) lint( text = 'expect_identical(typeof(x), \"double\")', linters = expect_type_linter() ) #> ::warning file=,line=1,col=1::file=,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t) # okay lint( text = 'expect_type(x, \"double\")', linters = expect_type_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"Invoking regular expression engine overkill cases search pattern involves static patterns.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"fixed_regex_linter(allow_unescaped = FALSE)"},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"allow_unescaped Logical, default FALSE. TRUE, patterns require regex escapes (e.g. \"\\\\$\" \"[$]\") linted. See examples.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"NB: stringr functions, means wrapping pattern stringr::fixed(). NB: linter likely able distinguish every possible case fixed regular expression preferable, rather seeks identify likely cases. never report false positives, however; please report false positives error.","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"best_practices, configurable, efficiency, readability, regex","code":""},{"path":"https://lintr.r-lib.org/dev/reference/fixed_regex_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Require usage of fixed=TRUE in regular expressions where appropriate — fixed_regex_linter","text":"","code":"# will produce lints code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x) lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[fixed_regex_linter] Use \".\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] Use \"a*b\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. lint( text = 'grepl(\"a[*]b\", x)', linters = fixed_regex_linter(allow_unescaped = TRUE) ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] Use \"a*b\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. code_lines <- 'stringr::str_subset(x, \"\\\\\\\\$\")' writeLines(code_lines) #> stringr::str_subset(x, \"\\\\$\") lint( text = code_lines, linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[fixed_regex_linter] Use stringr::fixed(\"$\") as the pattern here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter() ) #> ::warning file=,line=1,col=7::file=,line=1,col=7,[fixed_regex_linter] Use \"Munich\" with fixed = TRUE here. This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. # okay code_lines <- 'gsub(\"\\\\\\\\.\", \"\", x, fixed = TRUE)' writeLines(code_lines) #> gsub(\"\\\\.\", \"\", x, fixed = TRUE) lint( text = code_lines, linters = fixed_regex_linter() ) lint( text = 'grepl(\"a*b\", x, fixed = TRUE)', linters = fixed_regex_linter() ) lint( text = 'stringr::str_subset(x, stringr::fixed(\"$\"))', linters = fixed_regex_linter() ) lint( text = 'grepl(\"Munich\", address, fixed = TRUE)', linters = fixed_regex_linter() ) lint( text = 'grepl(\"Munich\", address)', linters = fixed_regex_linter(allow_unescaped = TRUE) )"},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"(x x) poor choice indexing variable. overwrites x calling scope confusing read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"for_loop_index_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"best_practices, readability, robustness","code":""},{"path":"https://lintr.r-lib.org/dev/reference/for_loop_index_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Block usage of for loops directly overwriting the indexing variable — for_loop_index_linter","text":"","code":"# will produce lints lint( text = \"for (x in x) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. lint( text = \"for (x in foo(x, y)) { TRUE }\", linters = for_loop_index_linter() ) #> ::warning file=,line=1,col=6::file=,line=1,col=6,[for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop. # okay lint( text = \"for (xi in x) { TRUE }\", linters = for_loop_index_linter() ) lint( text = \"for (col in DF$col) { TRUE }\", linters = for_loop_index_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function argument linter — function_argument_linter","title":"Function argument linter — function_argument_linter","text":"Check arguments defaults come last function declarations, per tidyverse design guide. Changing argument order can breaking change. alternative changing argument order instead set default arguments NULL.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function argument linter — function_argument_linter","text":"","code":"function_argument_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function argument linter — function_argument_linter","text":"best_practices, consistency, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_argument_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function argument linter — function_argument_linter","text":"","code":"# will produce lints lint( text = \"function(y = 1, z = 2, x) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=24::file=,line=1,col=24,[function_argument_linter] Arguments without defaults should come before arguments with defaults. lint( text = \"function(x, y, z = 1, ..., w) {}\", linters = function_argument_linter() ) #> ::warning file=,line=1,col=28::file=,line=1,col=28,[function_argument_linter] Arguments without defaults should come before arguments with defaults. # okay lint( text = \"function(x, y = 1, z = 2) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, w, z = 1, ...) {}\", linters = function_argument_linter() ) lint( text = \"function(y = 1, z = 2, x = NULL) {}\", linters = function_argument_linter() ) lint( text = \"function(x, y, z = 1, ..., w = NULL) {}\", linters = function_argument_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Function left parentheses linter — function_left_parentheses_linter","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Check left parentheses function call spaces (e.g. mean (1:3)). Although syntactically valid, makes code difficult read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"function_left_parentheses_linter()"},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Function left parentheses linter — function_left_parentheses_linter","text":"Exceptions made control flow functions (, , etc.).","code":""},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Function left parentheses linter — function_left_parentheses_linter","text":"default, readability, style","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_left_parentheses_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Function left parentheses linter — function_left_parentheses_linter","text":"","code":"# will produce lints lint( text = \"mean (x)\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=5::file=,line=1,col=5,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. lint( text = \"stats::sd(c (x, y, z))\", linters = function_left_parentheses_linter() ) #> ::warning file=,line=1,col=12::file=,line=1,col=12,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function call. # okay lint( text = \"mean(x)\", linters = function_left_parentheses_linter() ) lint( text = \"stats::sd(c(x, y, z))\", linters = function_left_parentheses_linter() ) lint( text = \"foo <- function(x) (x + 1)\", linters = function_left_parentheses_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":null,"dir":"Reference","previous_headings":"","what":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"return(x <- ...) either distracting (x ignored), confusing (assigning x side effect muddled dual-purpose expression).","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"function_return_linter()"},{"path":[]},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"tags","dir":"Reference","previous_headings":"","what":"Tags","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"best_practices, readability","code":""},{"path":"https://lintr.r-lib.org/dev/reference/function_return_linter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lint common mistakes/style issues cropping up from return statements — function_return_linter","text":"","code":"# will produce lints lint( text = \"foo <- function(x) return(y <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. lint( text = \"foo <- function(x) return(x <<- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=1,col=27::file=,line=1,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. writeLines(\"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\") #> e <- new.env() #> foo <- function(x) return(e$val <- x + 1) lint( text = \"e <- new.env() \\nfoo <- function(x) return(e$val <- x + 1)\", linters = function_return_linter() ) #> ::warning file=,line=2,col=27::file=,line=2,col=27,[function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether. # okay lint( text = \"foo <- function(x) return(x + 1)\", linters = function_return_linter() ) code_lines <- \" foo <- function(x) { x <<- x + 1 return(x) } \" lint( text = code_lines, linters = function_return_linter() ) code_lines <- \" e <- new.env() foo <- function(x) { e$val <- x + 1 return(e$val) } \" writeLines(code_lines) #> #> e <- new.env() #> foo <- function(x) { #> e$val <- x + 1 #> return(e$val) #> } #> lint( text = code_lines, linters = function_return_linter() )"},{"path":"https://lintr.r-lib.org/dev/reference/get_r_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract text from STR_CONST nodes — get_r_string","title":"Extract text from STR_CONST nodes — get_r_string","text":"Convert STR_CONST text() values R strings. useful account arbitrary character literals 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 <- tempfile() writeLines(\"c('a', 'b')\", tmp) expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content writeLines(as.character(expr_as_xml)) #> #> #> #> #> c<\/SYMBOL_FUNCTION_CALL> #> <\/expr> #> (<\/OP-LEFT-PAREN> #> #> 'a'<\/STR_CONST> #> <\/expr> #> ,<\/OP-COMMA> #> #> 'b'<\/STR_CONST> #> <\/expr> #> )<\/OP-RIGHT-PAREN> #> <\/expr> #> <\/exprlist> #> get_r_string(expr_as_xml, \"expr[2]\") #> [1] \"a\" get_r_string(expr_as_xml, \"expr[3]\") #> [1] \"b\" unlink(tmp) # more importantly, extract strings under R>=4 raw strings tmp4.0 <- tempfile() writeLines(\"c(R'(a\\\\b)', R'--[a\\\\\\\"\\'\\\"\\\\b]--')\", tmp4.0) expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content writeLines(as.character(expr_as_xml4.0)) #> #> #> #> #> c<\/SYMBOL_FUNCTION_CALL> #> <\/expr> #> (<\/OP-LEFT-PAREN> #> #> R'(a\\b)'<\/STR_CONST> #> <\/expr> #> ,<\/OP-COMMA> #> #> R'--[a\\\"'\"\\b]--'<\/STR_CONST> #> <\/expr> #> )<\/OP-RIGHT-PAREN> #> <\/expr> #> <\/exprlist> #> get_r_string(expr_as_xml4.0, \"expr[2]\") #> [1] \"a\\\\b\" get_r_string(expr_as_xml4.0, \"expr[3]\") #> [1] \"a\\\\\\\"'\\\"\\\\b\" unlink(tmp4.0)"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":null,"dir":"Reference","previous_headings":"","what":"Parsed sourced file from a filename — get_source_expressions","title":"Parsed sourced file from a filename — get_source_expressions","text":"object given input linter.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"get_source_expressions(filename, lines = NULL)"},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Parsed sourced file from a filename — get_source_expressions","text":"filename file parsed. lines character vector lines. NULL, filename read.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Parsed sourced file from a filename — get_source_expressions","text":"list three components: expressions list n+1 objects. first n elements correspond expression filename, consist list 8 elements: filename (character) name file. line (integer) line file expression begins. column (integer) column file expression begins. lines (named character) vector lines spanned expression, named corresponding line numbers. parsed_content (data.frame) given utils::getParseData() expression. xml_parsed_content (xml_document) XML parse tree expression given xmlparsedata::xml_parse_data(). content (character) lines single string (split across lines). xml_find_function_calls(function_names) (function) function returns SYMBOL_FUNCTION_CALL XML nodes xml_parsed_content specified function names. final element expressions list corresponding full file consisting 7 elements: filename (character) name file. file_lines (character) readLines() output file. content (character) .R files, file_lines; .Rmd .qmd scripts, extracted R source code (text). full_parsed_content (data.frame) given utils::getParseData() full content. full_xml_parsed_content (xml_document) XML parse tree expressions given xmlparsedata::xml_parse_data(). terminal_newline (logical) records whether filename terminal newline (determined readLines() producing corresponding warning). xml_find_function_calls(function_names) (function) function returns SYMBOL_FUNCTION_CALL XML nodes full_xml_parsed_content specified function names. error Lint object describing parsing error. lines readLines() output file.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Parsed sourced file from a filename — get_source_expressions","text":"file read using encoding setting. setting found taking first valid result following locations encoding key usual lintr configuration settings. Encoding field Package DESCRIPTION file parent directory. Encoding field R Project .Rproj file parent directory. \"UTF-8\" fallback.","code":""},{"path":"https://lintr.r-lib.org/dev/reference/get_source_expressions.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Parsed sourced file from a filename — get_source_expressions","text":"","code":"tmp <- tempfile() writeLines(c(\"x <- 1\", \"y <- x + 1\"), tmp) get_source_expressions(tmp) #> $expressions #> $expressions[[1]] #> $expressions[[1]]$filename #> [1] \"/tmp/RtmpLE85aI/file17295205609d\" #> #> $expressions[[1]]$line #> [1] 1 #> #> $expressions[[1]]$column #> [1] 1 #> #> $expressions[[1]]$lines #> 1 #> \"x <- 1\" #> #> $expressions[[1]]$parsed_content #> line1 col1 line2 col2 id parent token terminal text #> 7 1 1 1 6 7 0 expr FALSE #> 1 1 1 1 1 1 3 SYMBOL TRUE x #> 3 1 1 1 1 3 7 expr FALSE #> 2 1 3 1 4 2 7 LEFT_ASSIGN TRUE <- #> 4 1 6 1 6 4 5 NUM_CONST TRUE 1 #> 5 1 6 1 6 5 7 expr FALSE #> #> $expressions[[1]]$xml_parsed_content #> {xml_document} #> #> [1] \\n #> $expressions[[1]]$xml_find_function_calls #> function (function_names, keep_names = FALSE) #> { #> if (is.null(function_names)) { #> res <- function_call_cache #> } #> else { #> res <- function_call_cache[names(function_call_cache) %in% #> function_names] #> } #> if (keep_names) #> res #> else unname(res) #> } #> #> #> #> $expressions[[1]]$content #> [1] \"x <- 1\" #> #> #> $expressions[[2]] #> $expressions[[2]]$filename #> [1] \"/tmp/RtmpLE85aI/file17295205609d\" #> #> $expressions[[2]]$line #> [1] 2 #> #> $expressions[[2]]$column #> [1] 1 #> #> $expressions[[2]]$lines #> 2 #> \"y <- x + 1\" #> #> $expressions[[2]]$parsed_content #> line1 col1 line2 col2 id parent token terminal text #> 20 2 1 2 10 20 0 expr FALSE #> 10 2 1 2 1 10 12 SYMBOL TRUE y #> 12 2 1 2 1 12 20 expr FALSE #> 11 2 3 2 4 11 20 LEFT_ASSIGN TRUE <- #> 19 2 6 2 10 19 20 expr FALSE #> 13 2 6 2 6 13 15 SYMBOL TRUE x #> 15 2 6 2 6 15 19 expr FALSE #> 14 2 8 2 8 14 19 '+' TRUE + #> 16 2 10 2 10 16 17 NUM_CONST TRUE 1 #> 17 2 10 2 10 17 19 expr FALSE #> #> $expressions[[2]]$xml_parsed_content #> {xml_document} #> #> [1] \\n #> $expressions[[2]]$xml_find_function_calls #> function (function_names, keep_names = FALSE) #> { #> if (is.null(function_names)) { #> res <- function_call_cache #> } #> else { #> res <- function_call_cache[names(function_call_cache) %in% #> function_names] #> } #> if (keep_names) #> res #> else unname(res) #> } #> #> #> #> $expressions[[2]]$content #> [1] \"y <- x + 1\" #> #> #> $expressions[[3]] #> $expressions[[3]]$filename #> [1] \"/tmp/RtmpLE85aI/file17295205609d\" #> #> $expressions[[3]]$file_lines #> 1 2 #> \"x <- 1\" \"y <- x + 1\" #> attr(,\"terminal_newline\") #> [1] TRUE #> #> $expressions[[3]]$content #> 1 2 #> \"x <- 1\" \"y <- x + 1\" #> attr(,\"terminal_newline\") #> [1] TRUE #> #> $expressions[[3]]$full_parsed_content #> line1 col1 line2 col2 id parent token terminal text #> 7 1 1 1 6 7 0 expr FALSE #> 1 1 1 1 1 1 3 SYMBOL TRUE x #> 3 1 1 1 1 3 7 expr FALSE #> 2 1 3 1 4 2 7 LEFT_ASSIGN TRUE <- #> 4 1 6 1 6 4 5 NUM_CONST TRUE 1 #> 5 1 6 1 6 5 7 expr FALSE #> 20 2 1 2 10 20 0 expr FALSE #> 10 2 1 2 1 10 12 SYMBOL TRUE y #> 12 2 1 2 1 12 20 expr FALSE #> 11 2 3 2 4 11 20 LEFT_ASSIGN TRUE <- #> 19 2 6 2 10 19 20 expr FALSE #> 13 2 6 2 6 13 15 SYMBOL TRUE x #> 15 2 6 2 6 15 19 expr FALSE #> 14 2 8 2 8 14 19 '+' TRUE + #> 16 2 10 2 10 16 17 NUM_CONST TRUE 1 #> 17 2 10 2 10 17 19 expr FALSE #> #> $expressions[[3]]$full_xml_parsed_content #> {xml_document} #> #> [1] \\n