brace_linter | R Documentation |
Perform various style checks related to placement and spacing of curly braces:
brace_linter(allow_single_line = FALSE)
allow_single_line |
if |
Opening curly braces are never on their own line and are always followed by a newline.
Opening curly braces have a space before them.
Closing curly braces are on their own line unless they are followed by an else
.
Closing curly braces in if
conditions are on the same line as the corresponding else
.
Either both or neither branch in if
/else
use curly braces, i.e., either both branches use {...}
or neither
does.
Functions spanning multiple lines use curly braces.
configurable, default, readability, style
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "f <- function() { 1 }",
linters = brace_linter()
)
writeLines("if (TRUE) {\n return(1) }")
lint(
text = "if (TRUE) {\n return(1) }",
linters = brace_linter()
)
# okay
writeLines("f <- function() {\n 1\n}")
lint(
text = "f <- function() {\n 1\n}",
linters = brace_linter()
)
writeLines("if (TRUE) { \n return(1) \n}")
lint(
text = "if (TRUE) { \n return(1) \n}",
linters = brace_linter()
)
# customizing using arguments
writeLines("if (TRUE) { return(1) }")
lint(
text = "if (TRUE) { return(1) }",
linters = brace_linter(allow_single_line = TRUE)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.