7

Is there an r code I can use that will remove all of the comments from an .r file?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Tal Galili
  • 24,605
  • 44
  • 129
  • 187

1 Answers1

10

See tidy.source() in the formatR package, option keep.comment = FALSE

And an example.... copy and paste the following (including the comment). Tidy source defaults to reading the clipboard for the code.

# This is a useless comment
for(i in 1:5){
  print(i)
}

and then

> library(formatR)
> tidy.source(keep.comment = FALSE)
for (i in 1:5) {
    print(i)
} 
Rguy
  • 1,622
  • 1
  • 15
  • 20