## Keep parse data in non interactive sessions.
if (!interactive())
op <- options(keep.source = TRUE)
## Correct positioning of braces in R bracing style
fil <- tempfile(fileext = ".R")
cat("x <- 2",
"if (x <= 2)",
"{",
" y <- 3",
" x + y",
"}",
file = fil, sep = "\n")
srcData <- getSourceData(fil)
open_brace_style(srcData, style = "R")
close_brace_style(srcData)
## Above code in invalid in 1TBS bracing style
open_brace_style(srcData, style = "1TBS")
## Incorrect positioning of the opening brace and
## misalignment of the closing brace
fil <- tempfile(fileext = ".R")
cat("f <- function(x) {",
" x^2",
" }",
file = fil, sep = "\n")
srcData <- getSourceData(fil)
open_brace_style(srcData, style = "R")
close_brace_style(srcData)
## Incorrect simultaneous use of two bracing styles
fil <- tempfile(fileext = ".R")
cat("x <- 2",
"if (x <= 2)",
"{",
" y <- 3",
" x + y",
"}",
"for (i in 1:5) {",
" x + i",
"}",
file = fil, sep = "\n")
open_brace_unique_style(getSourceData(fil))
Run the code above in your browser using DataLab