library(formatR)
src = c("# a single line of comments is preserved",
"1+1", "", "if(TRUE){", "x=1 # inline comments!", "}else{",
"x=2;print('Oh no... ask the right bracket to go away!')}",
"2+2+2 # 'short comments'", "lm(y~x1+x2) ### only 'single quotes' are allowed in comments",
"1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1 ## comments after a long line")
x = tidy.source(text = src, output = FALSE)$text.mask
cat(x, sep = "\n")
cat(unmask.source(x), sep = "\n")Run the code above in your browser using DataLab