pipe_return_linter | R Documentation |
return()
inside a magrittr pipeline does not actually execute return()
like you'd expect: \(x) { x %>% return(); FALSE }
will return FALSE
!
It will technically work "as expected" if this is the final statement
in the function body, but such usage is misleading. Instead, assign
the pipe outcome to a variable and return that.
pipe_return_linter()
best_practices, common_mistakes
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "function(x) x %>% return()",
linters = pipe_return_linter()
)
# okay
code <- "function(x) {\n y <- sum(x)\n return(y)\n}"
writeLines(code)
lint(
text = code,
linters = pipe_return_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.