I'm writing R scripts in RStudio and I use the code folding a lot. I found that you can see the hierarchy of the folding by pressing cmd + shift + O. This is super helpful.
# to my dear love --------------------------------------------------------- 2+2 # yo man ==== x.2 = function (x) {x+2} ### I do love potatoes ####
See the result by pressing cmd + shift + O.
I don't understand how this is working because when I write the code below, I can create a subsection without text but not when there is text in it (using # ====
but not # yo man ====
).
# to my dear love --------------------------------------------------------- 2+2 # ==== # yo man ==== ### I do love potatoes #### x.2 = function (x) {x+2} data = "here is some data"
See the result by pressing cmd + shift + O.
You can see that under # to my dear love ---------------------------------------------------------
everything under is shifted to the right! This is cool!
As per Chris's answer subheaders within functions
RStudio Code Folding hierarchy only works within function definitions and if-else structures. For example:
# Section 1 ---- a <- 1 testfunct1 <- function () { # sect in function===== b <- 2 c <- 3 } # Section 2 ##### d <- 4 # Section 3 ======= e <- 5 testfunct2 <- function () { # sect in function 2 ===== f <- 6 testsubfunct2_1 <- function () { # sect in subfunction 2_1 ----- if (a == 1) { # section in if ---- g < 7 } else { # section in else ---- h = 8 } } } # Section 4 #### j <- 9
Produces this outline:
I don't know why the if-else section labels do not line up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With