View source: R/implicit_assignment_linter.R
implicit_assignment_linter | R Documentation |
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()
).
implicit_assignment_linter(
except = c("bquote", "expression", "expr", "quo", "quos", "quote"),
allow_lazy = FALSE,
allow_scoped = FALSE
)
except |
A character vector of functions to be excluded from linting. |
allow_lazy |
logical, default |
allow_scoped |
Logical, default |
best_practices, configurable, readability, style
linters for a complete list of linters available in lintr.
# 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)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.