View source: R/coalesce_linter.R
coalesce_linter | R Documentation |
%||%
The x %||% y
is equivalent to
if (is.null(x)) y else x
, but more expressive.
It is exported by R since 4.4.0, and equivalents
have been available in other tidyverse packages
for much longer, e.g. 2008 for ggplot2.
coalesce_linter()
best_practices, consistency, readability
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "if (is.null(x)) y else x",
linters = coalesce_linter()
)
lint(
text = "if (!is.null(x)) x else y",
linters = coalesce_linter()
)
lint(
text = "if (is.null(x[1])) x[2] else x[1]",
linters = coalesce_linter()
)
# okay
lint(
text = "x %||% y",
linters = coalesce_linter()
)
lint(
text = "x %||% y",
linters = coalesce_linter()
)
lint(
text = "x[1] %||% x[2]",
linters = coalesce_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.