View source: R/redundant_ifelse_linter.R
redundant_ifelse_linter | R Documentation |
ifelse()
from being used to produce TRUE
/FALSE
or 1
/0
Expressions like ifelse(x, TRUE, FALSE)
and ifelse(x, FALSE, TRUE)
are
redundant; just x
or !x
suffice in R code where logical vectors are a
core data structure. ifelse(x, 1, 0)
is also as.numeric(x)
, but even
this should be needed only rarely.
redundant_ifelse_linter(allow10 = FALSE)
allow10 |
Logical, default |
best_practices, configurable, consistency, efficiency
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "ifelse(x >= 2.5, TRUE, FALSE)",
linters = redundant_ifelse_linter()
)
lint(
text = "ifelse(x < 2.5, 1L, 0L)",
linters = redundant_ifelse_linter()
)
# okay
lint(
text = "x >= 2.5",
linters = redundant_ifelse_linter()
)
# Note that this is just to show the strict equivalent of the example above;
# converting to integer is often unnecessary and the logical vector itself
# should suffice.
lint(
text = "as.integer(x < 2.5)",
linters = redundant_ifelse_linter()
)
lint(
text = "ifelse(x < 2.5, 1L, 0L)",
linters = redundant_ifelse_linter(allow10 = TRUE)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.