unnecessary_nested_if_linter | R Documentation |
if
conditional statementsAvoid unnecessary nested if
conditional statements
unnecessary_nested_if_linter()
best_practices, readability
linters for a complete list of linters available in lintr.
# will produce lints
writeLines("if (x) { \n if (y) { \n return(1L) \n } \n}")
lint(
text = "if (x) { \n if (y) { \n return(1L) \n } \n}",
linters = unnecessary_nested_if_linter()
)
# okay
writeLines("if (x && y) { \n return(1L) \n}")
lint(
text = "if (x && y) { \n return(1L) \n}",
linters = unnecessary_nested_if_linter()
)
writeLines("if (x) { \n y <- x + 1L\n if (y) { \n return(1L) \n } \n}")
lint(
text = "if (x) { \n y <- x + 1L\n if (y) { \n return(1L) \n } \n}",
linters = unnecessary_nested_if_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.