Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing all comments from an .r file?

Tags:

r

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

like image 574
Tal Galili Avatar asked Dec 13 '11 21:12

Tal Galili


1 Answers

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)
} 
like image 158
Rguy Avatar answered Oct 03 '22 16:10

Rguy