7

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

ROMANIA_engineer
  • 51,252
  • 26
  • 196
  • 186
Tal Galili
  • 23,433
  • 41
  • 122
  • 183

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,602
  • 1
  • 15
  • 20