Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a hashtag # sign to many lines in r command?

Tags:

r

I want to add hashtag # sign before many lines in r. How can I do it using a shortcut key?

like image 690
Minoo Avatar asked Aug 07 '15 13:08

Minoo


3 Answers

R Studio: Highlight the text and use CTRL+SHIFT+C to comment multiple lines.

like image 188
Imran Ali Khan Avatar answered Oct 08 '22 08:10

Imran Ali Khan


I know this is slightly different to the question asked but after multiple failed searches on stackoverflow for a solution to my question, all which ended up on this page, I thought I would add this for anyone in a similar situation. I was looking for a quick way (purely for aesthetic commenting reasons) to add a line of #### across a R script, rather than holding down the # button, I came across the bannerCommenter package which I think is really useful. It also has other formats.

    library(bannerCommenter)
    #run the following command which saves the comment to clipboard
    #then just paste on next line of script
    banner("Section 1:", "Data input and initialization", emph = TRUE) 

    ###########################################################################
    ###########################################################################
    ###                                                                     ###
    ###                              SECTION 1:                             ###
    ###                 DATA INPUT AND INITIALIZATION                       ###
    ###                                                                     ###
    ###########################################################################
    ###########################################################################
like image 35
user63230 Avatar answered Oct 08 '22 07:10

user63230


rather than multiple "#", i prefer to use ' (apostrof) between lines to disable it. for example:

'dim(train);dim(test)
names(train)
names(test)
str(train)
str(test)'

in R console, 5 lines above will return:

> 'dim(train);dim(test)
+ names(train)
+ names(test)
+ str(train)
+ str(test)'
[1] "dim(train);dim(test)\nnames(train)\nnames(test)\nstr(train)\nstr(test)"
> 
like image 1
nashihu Avatar answered Oct 08 '22 08:10

nashihu