Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rstudio - keeping code folded when run / file closed

Tags:

r

rstudio

This question appears to be mentioned briefly here - Permanent Code Folding in RStudio - however for windows and a bit outdated. I am on OS X with RStudio version 0.99.891.

I use command-alt-L to fold code in R-studio, and would prefer if the code remains folded when I both (1) save/close/reopen the file, and (2) run the folded code. Currently, doing both (1) and (2) unfolds the code, which is slightly frustrating.

Anyone know if this is avoidable, or something I should learn to live with?

Thanks!

like image 484
Canovice Avatar asked Aug 23 '16 16:08

Canovice


People also ask

How do I run an entire code in RStudio?

In addition, in Rstudio you can run the entire script by pressing Ctrl + Shift + Enter without selecting any code. In addition, there is a shortcut to source the current script file ( Ctrl + Shift + s ), which runs the script without echoing each line.

How do I group a line of code in R?

The easiest way to create a multi-line comment in RStudio is to highlight the text and press Ctrl + Shift + C. You can just as easily remove the comment by highlighting the text again and pressing Ctrl + Shift + C.

How do I name a section in R script?

In latest R Studio (I work with v1. 0+), you can also click Ctrl + Shift + R , or go to menu Code > Insert Section . It will show a popup for your section name and add it. The title will then have a tiny arrow to hide the entire section until the next title.


1 Answers

If you put # #### around every bit you want to fold and then when you open the script Alt+O (Cmd+Option+O on Mac) that will fold everything. Then highlighting the line and running it keeps it folded.

like image 183
USER_1 Avatar answered Sep 30 '22 16:09

USER_1