When writing large R scripts, the document outline can be extremely helpful, especially nesting the headers to achieve a nice easily-navigated hierarchical structure
When all headers are located outside of code, this nesting works nicely:
# Header 1 ----
## Sub-header A ----
## Sub-header B ----
# Header 2 ----
produces:
- Header 1
- Sub-header A
- Sub-header B
- Header 2
However, when headers are located inside of nested code, the code hierarchy overrides the nesting of the headers:
# Header 1 ----
if(condition) {
## Sub-header A ----
if(A) {
#do something
## Sub-header B ----
} else if (B) {
#do something
}
# Header 2 ----
} else {
#do something
}
produces:
- Header 1
- Sub-header A
- Sub-header B
- Header 2
- Sub-header A
I would propose that there be some way of allowing headers to set their nesting level regardless of the code they're located in. Perhaps some additional character that forces things so that the number of #
sets the hierarchical level of the outline regardless of where they are in the code