For details about this indentation pattern called "Whitesmith", please see: http://www.activeclickweb.com/whitesmiths/index.html or https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_style
Using R, here is an example basic function using this indentation style:
# this is "not" recursive at the moment ...
createDir = function (folder)
{
ifelse(!dir.exists(folder), dir.create(folder), "Folder exists already")
}
Here is a switch statement inside a function using the same style:
buildX = function(n,method)
{
switch(method,
"rnorm-0-1" = rnorm(n,0,1),
"rgama-1-0.5" = rgamma(n,1,1/2),
rnorm(n,0,1) # default case of switch
);
}
Here is another function, to conclude the examples:
buildY = function(resp, n, unif, myQ)
{
Y = numeric(n);
for (i in 1:n)
{
Y[i] = mapY(i, unif, myQ, resp);
}
Y;
}
How do I configure RStudio to use this indentation style? Will it work when I copy an paste?
And bonus for an answer to the ability to highlight the two braces more readily, like Notepad++ does? I can click on the right/left side of the open/close brace and it highlights, and even creates a vertical line connecting the braces ...