Descriptive text for Collapsed Regions

rstudio
feature-request

#1

I'm a new user, and limited to posting only one image per post. I need to include several, so I screenshotted my entire comment into one picture:

It's confusing to work in the IDE when many regions are collapsed. They all look the same, especially when working with Rmarkdown and having many code chunks.


#2

Hi @haakonstorm! Welcome!

You can give each R Markdown chunk a label. Besides helping to distinguish between the chunks when collapsed, this also improves the display of the jump-to navigation menu:

40

Chunk labels are also used as the basis for figure output file names. The rules for chunk labels are discussed here: https://bookdown.org/yihui/rmarkdown/r-code.html


By the way: I know it's frustrating to not be able to post more images as a new user, but it's really hard to read text that's been put into an image (and it's not searchable at all). Can you please copy the text from your image back into the post?


#3

Thank you for taking the time to answer.
I know I can name chunks, I should have named the chunks in my example to make what I want more visible.

In the link you refer about chunk labels you can read:

Chunk labels are mainly used in filenames of plots and cache. If the label of a chunk is missing, a default one of the form unnamed-chunk-i will be generated, where i is incremental. I strongly recommend that you only use alphanumeric characters ( a-z , A-Z and 0-9 ) and dashes ( - ) in labels, because they are not special characters and will surely work for all output formats. Other characters, spaces and underscores in particular, may cause trouble in certain packages, such as bookdown ."

You are suggesting I use long form descriptive text as the label name of a chunk.
This is not a good solution.
What I want is to separate my code from the commenting of my code.

Also, I use code folding to hide complexity.

A long form comment on the second line on the chunk could replace the entire first line.
This would hide more of the complexity and increase readibility a lot.

Also, the Folding functionality could be expanded even further to be even more useful, especially in Rmarkdown contexts - you can use Rstudio as an outlining tool; Fold structures and then reorder them with drag and drop. If the Folding works as I suggest, you can drag and drop the entire line up and down to reorder your document, instead of copy+paste and make sure the icon representing the folded text stays where it should.

(EDIT: I'll edit my first comment later to put all pictures in to one, and clafiry what I'm suggesting as a feature)


#4

Not at all! That would indeed be a pretty questionable idea :grin:. I was suggesting a workaround for the problem you initially described:

Chunk labels don't allow for the kind of lengthy description you seem to be envisioning, but they do keep all the collapsed chunks from looking the same.

Your feature idea is interesting, but I'm not sure I totally understand how you're imagining it working. Maybe the updated images will help! But this part puzzles me a bit:

Again, perhaps I'm misunderstanding, but this sounds like it's heading right in the direction of literate programming... which is what R Markdown (and knitr) already do. How do you see comments as being distinct from explanatory text outside of code chunks?


#5

I personally prefer the short label feature to keep track of what code chuck does what. But you can always just add comments above or below your code chunk;


#6

Just as an FYI, descriptive text is totally fine, as long as it conforms to chunk-naming standards (I believe that means they can only have words and hyphens).

One way to get easier visibility and navigation in your Rmd is to change your outline options so that you can see named chunks (or all chunks) in addition to sections in the outline to the right of the editor:

RStudio >> Preferences >> R Markdown


#7

I made an example in a macOS-based outline utility called OmniOutliner.

See: https://www.youtube.com/watch?v=a-6Or-Et8SY&feature=youtu.be

Still, the second line after each R code chunk could be a comment, and render as the name of the Folded region. This would help readability a lot when using Rstudio e.g. when writing reports when text is the main focus.

R, Rstudio and Rmarkdown is awesome as it is.
I'm trying to migrate all my workflows over to Rstudio.
Version control with git, mixing of markdown, code, results of code, knitting to PDF, html ... mmmh


#8

You can certainly submit this as a feature request in the IDE GitHub repo. There's a nice guide, too.
RStudio IDE Guide: Writing Good Feature Requests


#9

Thank you mara, I submitted this as feature request in the repo: