implicit_assignment_linter {lintr} | R Documentation |
Avoid implicit assignment in function calls
Description
Assigning inside function calls makes the code difficult to read, and should
be avoided, except for functions that capture side-effects (e.g. capture.output()
).
Usage
implicit_assignment_linter(
except = c("bquote", "expression", "expr", "quo", "quos", "quote"),
allow_lazy = FALSE,
allow_scoped = FALSE
)
Arguments
except |
A character vector of functions to be excluded from linting. |
allow_lazy |
logical, default |
allow_scoped |
Logical, default |
Tags
best_practices, configurable, readability, style
See Also
-
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "if (x <- 1L) TRUE",
linters = implicit_assignment_linter()
)
lint(
text = "mean(x <- 1:4)",
linters = implicit_assignment_linter()
)
# okay
lines <- "x <- 1L\nif (x) TRUE"
writeLines(lines)
lint(
text = lines,
linters = implicit_assignment_linter()
)
lines <- "x <- 1:4\nmean(x)"
writeLines(lines)
lint(
text = lines,
linters = implicit_assignment_linter()
)
lint(
text = "A && (B <- foo(A))",
linters = implicit_assignment_linter(allow_lazy = TRUE)
)
lines <- c(
"if (any(idx <- x < 0)) {",
" stop('negative elements: ', toString(which(idx)))",
"}"
)
writeLines(lines)
lint(
text = lines,
linters = implicit_assignment_linter(allow_scoped = TRUE)
)
[Package lintr version 3.1.2 Index]