Reputation: 1363
I'm using RStudio 1.4.1106 for MacOS.
I'm continuing with writing my package functions. Some of them are quite long and involve branching methods depending on the nature of the input data. The branching involves if loops, and there are sub-if loops as well.
I comment the close brackets so I can back track to the start line of the loop (I don't use line numbers because I am frequently modifying code and the line numbers change). My current method to verify I have the correct loop selected is to go to the left of the close bracket and then identify the open bracket by the fact it is highlighted.
Is there a method of highlighting an entire loop code block? In particular, this would make it easier for me to comment out an entire block of code without worrying I have commented out too much or too little.
Upvotes: 1
Views: 731
Reputation: 797
There are a few things that will make your life easier:
There are arrows next to the line numbers that will collapse a code block (I think determined by the braces {}
). You can collapse from the top (e.g. line 109 in the screenshot attached) or the bottom (line 125 in the screenshot).
The other thing that can help if you want to examine code within a block is that double clicking just before or after the opening or closing brace will highlight all the code enclosed by the matching braces. See second screenshot below: .
Edit: Just noticed the comment - as mentioned you can also highlight code while the section is collapsed, and it will stay highlighted when expanded.
Upvotes: 1