Search code examples
rrstudioauto-indentcode-folding

Indenting code within .R script without using a function


I am new to R, and despite searching the forums I have been unable to find a solution to indenting code within both the Source window and Document Outline (Ctrl+Shift+O).

An example is shown below.

img1

Ideally, I would want the code to function as below when pressing Alt+O

img2

This function does seem to be implemented in some fashion as you get the indented code with functions but this is less than ideal.

    # Section 1 ----------------------------------------------------------- 
    function(x) {
    # Section 1A  ===========================================================
    }

Has anyone found a work-around to implement this?


Solution

  • Thanks @Foztarz I posted this as an issue about a year ago on the GitHub. They claimed it was a worthy enhancement but they keep pushing it to the next version of RStudio lol. My work-around was similar. I used Alt codes to insert symbols I found a bit more visually appealing over .

     # ▬ Section A ------
    
    
        # ▐ ▬ Section A.1-----------
    

    Here's what it looks like inside RStudio

    enter image description here