View source: R/return_linter.R
return_linter | R Documentation |
This linter checks functions' return()
expressions.
return_linter(
return_style = c("implicit", "explicit"),
allow_implicit_else = TRUE,
return_functions = NULL,
except = NULL,
except_regex = NULL
)
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
|
configurable, default, style
linters for a complete list of linters available in lintr.
# 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)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.