"Insert section" not working in Rstudio Version 1.1.456

Hi, I have just discovered (from https://support.rstudio.com/hc/en-us/articles/200484568-Code-Folding-and-Sections) the option to insert sections. However, I can neither see an option under the Code menu for 'Insert Section' nor use the shortcut Ctrl+Shift+R. Using the format of a # at the start of a line with dashes or other trailing symbols does not automatically create a section either.

i am using Rstudio Version 1.1.456 with an Rhtml file on Wondows 10.

Any suggestions as to how i might get sections to work?

Thanks,
Adrian.

Hi Adrian! Welcome!

Have you tried inserting section separators when you have a regular R script file open? RStudio’s code options are contextual to some extent. In an R HTML file, as in an R Markdown file, Insert Section is replaced by Insert Chunk in the Code menu.

If you are editing the HTML portion of an R HTML document, then those separators won’t make sense (comments are bracketed with <!-- and -->, like in regular HTML). Meanwhile, document wide code regions already exist in the form of chunks (which can be folded and show up in the jump to menu like sections would). I suspect it would be rather complex to have a second tier of code regions within chunks.

Hi jcblum, erm, well that was an obvious thing I didn’t try! Yes, it does work with just regular Rscript so its just an issue with Rhtml. I can fold sections manually in Rhtml (using Folding:Collapse in the edit menu) but those folds disappear as soon as you unfold, but nonetheless useful for bits of code I’m not working on. I don’t need to fold within chunks, just need to fold multiple whole chunks together.

Thanks for your quick and helpful reply.

Adrian.

1 Like