Tips/best practice for separating chunks of code in RStudio? Cleaning code

Hello,

I find that it becomes difficult to present my code cleanly due to the many different sections. Each section contains minimal comments and lines of code, but between the sections I only have a few line breaks.

I like how Markdown can split code into chunks with titles explaining what the code does, and highlights different sections using slightly different colors.

Is there anything like that for non-markdown code in RStudio? Do other people just use some sort of commented lines? I currently do something like this:

#This is section 1. It does abc

#codecodecodecodecodecodecodecode
#codecodecodecodecodecodecodecode
#codecodecodecodecodecodecodecode
#codecodecodecodecodecodecodecode

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#This is section 2. It does xyz

#codecodecodecodecodecodecodecode
#codecodecodecodecodecodecodecode
#codecodecodecodecodecodecodecode
#codecodecodecodecodecodecodecode

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hello,

I recommend you to take a look to the STRCODE Addin
(see here)

1 Like

After a while of searching Google and forums, I was still unaware that something like this existed. Thank you!

There is also the Insert Section... command in the Code menu, which will automatically insert a named comment break and anchor.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.