packageVersion("lintr")
#> [1] '3.0.2.9000'
text <- "
list(
dplyr::if_else(c(TRUE, FALSE, NA), TRUE, FALSE),
dplyr::if_else(c(TRUE, FALSE, NA), TRUE, FALSE, TRUE),
dplyr::if_else(c(TRUE, FALSE, NA), TRUE, FALSE, FALSE),
dplyr::if_else(c(TRUE, FALSE, NA), 1, 0),
dplyr::if_else(c(TRUE, FALSE, NA), 1, 0, 2)
)
"
lintr::lint(text = text, linters = lintr::redundant_ifelse_linter())
#> <text>:3:3: warning: [redundant_ifelse_linter] Just use the logical condition (or its negation) directly instead of calling if_else(x, TRUE, FALSE)
#> dplyr::if_else(c(TRUE, FALSE, NA), TRUE, FALSE),
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#> <text>:4:3: warning: [redundant_ifelse_linter] Just use the logical condition (or its negation) directly instead of calling if_else(x, TRUE, FALSE)
#> dplyr::if_else(c(TRUE, FALSE, NA), TRUE, FALSE, TRUE),
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#> <text>:5:3: warning: [redundant_ifelse_linter] Just use the logical condition (or its negation) directly instead of calling if_else(x, TRUE, FALSE)
#> dplyr::if_else(c(TRUE, FALSE, NA), TRUE, FALSE, FALSE),
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#> <text>:6:3: warning: [redundant_ifelse_linter] Prefer as.numeric(x) to if_else(x, 1, 0) if really needed.
#> dplyr::if_else(c(TRUE, FALSE, NA), 1, 0),
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#> <text>:7:3: warning: [redundant_ifelse_linter] Prefer as.numeric(x) to if_else(x, 1, 0) if really needed.
#> dplyr::if_else(c(TRUE, FALSE, NA), 1, 0, 2)
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
eval(parse(text = text))
#> [[1]]
#> [1] TRUE FALSE NA
#>
#> [[2]]
#> [1] TRUE FALSE TRUE
#>
#> [[3]]
#> [1] TRUE FALSE FALSE
#>
#> [[4]]
#> [1] 1 0 NA
#>
#> [[5]]
#> [1] 1 0 2
The
redundant_ifelse_linter()ignoresdplyr::if_else()'smissingarg and suggests a correction which would change the results.Created on 2023-03-30 with reprex v2.0.2