Multiline Comment Workarounds?

后端 未结 10 1097
轮回少年
轮回少年 2020-11-30 18:36

I (sort of) already know the answer to this question. But I figured it is one that gets asked so frequently on the R Users list, that there should be one solid good answer.

相关标签:
10条回答
  • 2020-11-30 19:01

    This does come up on the mailing list fairly regularly, see for example this recent thread on r-help. The consensus answer usually is the one shown above: that given that the language has no direct support, you have to either

    • work with an editor that has region-to-comment commands, and most advanced R editors do
    • use the if (FALSE) constructs suggested earlier but note that it still requires complete parsing and must hence be syntactically correct
    0 讨论(0)
  • 2020-11-30 19:03

    In RStudio an easy way to do this is to write your comment and once you have used CTRL + Shift + C to comment your line of code, then use CTRL + SHIFT + / to reflow you comment onto multiple lines for ease of reading.

    0 讨论(0)
  • 2020-11-30 19:06

    A neat trick for RStudio I've just discovered is to use #' as this creates an self-expanding comment section (when you return to new line from such a line or insert new lines into such a section it is automatically comment).

    0 讨论(0)
  • 2020-11-30 19:07

    I use vim to edit the R script.

    Let's say the R script is test.R, containing say "Line 1", "Line 2", and "Line 3" on 3 separate lines.

    I open test.R on the command line with Vim by typing "vim test.R". Then I go to the 1st line I want to comment out, type "Control-V", down arrow to the last line I want to comment out, type a capital I i.e. "I" for insert, type "# ", and then hit the Escape key to add "# " to every line that I selected by arrowing down. Save the file in Vim and then exit Vim by typing ":wq". Changes should show up in Rstudio.

    To delete the comments in Vim, start at the first line on top of the character "#" you want to delete, again do "Control-V", and arrow down to the last line you want to delete a "#" from. Then type "dd". The "#" signs should be deleted.

    There's seconds-worth of lag time between when changes to test.R in Vim are reflected in Rstudio.

    0 讨论(0)
提交回复
热议问题