View source: R/scalar_in_linter.R
| scalar_in_linter | R Documentation |
vector %in% set is appropriate for matching a vector to a set, but if
that set has size 1, == is more appropriate. However, if vector has
also size 1 and can be NA, the use of == should be accompanied by extra
protection for the missing case (for example, isTRUE(NA == "arg") or
!is.na(x) && x == "arg").
scalar_in_linter(in_operators = NULL)
in_operators |
Character vector of additional infix operators that behave like the |
scalar %in% vector is OK, because the alternative (any(vector == scalar))
is more circuitous & potentially less clear.
best_practices, configurable, consistency, efficiency, readability
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "x %in% 1L",
linters = scalar_in_linter()
)
lint(
text = "x %chin% 'a'",
linters = scalar_in_linter(in_operators = "%chin%")
)
# okay
lint(
text = "x %in% 1:10",
linters = scalar_in_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.