I would like to use the document outline feature in RStudio to more effectively allow my code reviewer to navigate a file, but my outline is not indenting like I would expect it to. I'm wondering if it's possible to get the output I want by changing my syntax. I posted this question to stackoverflow with pictures, it might be easier to see there. I put the code below with an example of what I would like the outline to look like at the bottom. Thanks for your help!
Paste code below and hit ctrl+shift+O, first few sections are indented under my_function, but then the remaining sections are even with my_function, not sure why since they are also nested inside my_function.
my_function <- function(x,y){
# Unconditional ====
print("Set some variables for the function")
# Condition 1 ====
if(x>100){
# Action 1 ====
print("Do some stuff to x")
# Action 2 ====
z <- x*pi
}
# Condition 2 ====
else if(y<=100){
# Action 1 ====
print("Do some stuff to x")
# Action 2 ====
z <- psigamma(y)
}
# Condition 3 ====
else if(x<=100){
# Action 1 ====
print("Do some stuff to x")
# Action 2 ====
z <- x+100
}
# Otherwise ====
else{
z <- x+y
}
return(z)
}
I would like the outline to look like this:
my_function
- Unconditional
- Condition 1
-- Action 1
-- Action 2 - Condition 2
-- Action 1
-- Action 2 - Condition 3
-- Action 1
-- Action 2 - Otherwise