return_linter {lintr} | R Documentation |
Return linter
Description
This linter checks functions' return()
expressions.
Usage
return_linter(
return_style = c("implicit", "explicit"),
allow_implicit_else = TRUE,
return_functions = NULL,
except = NULL,
except_regex = NULL
)
Arguments
return_style |
Character string naming the return style. |
allow_implicit_else |
Logical, default |
return_functions |
Character vector of functions that are accepted as terminal calls
when |
except , except_regex |
Character vector of functions that are not checked when
|
Tags
See Also
-
linters for a complete list of linters available in lintr.
Examples
# will produce lints
code <- "function(x) {\n return(x + 1)\n}"
writeLines(code)
lint(
text = code,
linters = return_linter()
)
code <- "function(x) {\n x + 1\n}"
writeLines(code)
lint(
text = code,
linters = return_linter(return_style = "explicit")
)
code <- "function(x) {\n if (x > 0) 2\n}"
writeLines(code)
lint(
text = code,
linters = return_linter(allow_implicit_else = FALSE)
)
# okay
code <- "function(x) {\n x + 1\n}"
writeLines(code)
lint(
text = code,
linters = return_linter()
)
code <- "function(x) {\n return(x + 1)\n}"
writeLines(code)
lint(
text = code,
linters = return_linter(return_style = "explicit")
)
code <- "function(x) {\n if (x > 0) 2 else NULL\n}"
writeLines(code)
lint(
text = code,
linters = return_linter(allow_implicit_else = FALSE)
)