Wish: Store state of collapsible code tree

In Visual Studio, I used the collapsible code tree all the time, because it is persistent after a reload.

In RStudio, collapsible tree is almost useless, because it is gone on reload.


I was thinking about that, too. I work a lot with long data notebooks and all the scrolling up and down does add up.

Can you elaborate on what you mean by 'collapsible tree'? Do you mean code folding (whereby you can e.g. click the arrow icon in the gutter to hide a section of code), or possibly something else?

These folds are typically preserved across sessions (ie, you should see the folds restored after closing and re-opening the RStudio IDE), although they are indeed lost after closing the document. Is that perhaps what you are referring to?

Sorry for the wrong term... yes, code folding.

Version 1.1.359, Desktop, Windows. In this settings, when I start a project even the last file does not reopen, and I have never seen code folding being restored. Did I miss some setting? I never save/restore rdata, but I assume this is the default anyway.

There's a UI preference that handles this (Tools -> Global Options...), called:

  • Restore previously open source documents at startup

See the third checkbox from the top here:

Is that option checked on your system? If not, that might explain the behavior you're seeing.


Bingo! I am using RStudio since version 0.1, and never had this ticked. I normally clicke on the project to start, so I thought it means "Reload last file" when RStudio is started without project.

Maybe better: Restore state of loaded document?


I have that option activate (MAC, Rstudio Version 1.1.383) and it's not working the way I need it to.

My wished usage is: Within a project, if I save my .R file with folds collapsed, close it, open it again, I want to see those those in the same state. That is not the case for me.

What works is : close project, open project, I find my folds in the same state I left them when I closed.
Why it's not enough: simply because I open and close .R files all the time within a session and this resets the folding every time.

Here's a shot of my state of preferences:

I'm sure I'm missing something, thank you for your help.

Unfortunately, folds are currently lost after a file is closed in the IDE; in general, state related to a document (folds, cursor position) does not persist after the file has been closed in the IDE.

Thank you for the answer.
Where would be the best place to wish/vote for the feature?
I understand one is expected to put as many functions in separate source files, but especially for reactive statements it's not always convenient and keeping as many blocks folded eases readability a lot. I really think the feature is legitimate.

I agree this is worth requesting -- you can create a feature request directly at https://github.com/rstudio/rstudio/issues.