[ESS] Indent for R's 'switch'

Marius Hofert m@r|u@@ho|ert @end|ng |rom uw@ter|oo@c@
Fri Jun 22 17:06:33 CEST 2018


Hi Alex,

thanks for your quick reply. You are right, I used "(setq
ess-default-style 'C++)", so it's a problem of the C++ style.
Thanks for pointing this out.

I can confirm that the problem does not exist in the default style
(although all cases are indented then, which is a bit of a waste of
space since often one has constructions like "my_variable_value <-
switch(...)" and so everything is indented quite a bit; would still
find it elegant to have the cases aligned with 'switch')

Cheers,
Marius

On Fri, Jun 22, 2018 at 10:54 AM Alex Branham <alex.branham using gmail.com> wrote:
>
>
> On Fri 22 Jun 2018 at 09:50, Marius Hofert via ESS-help <ess-help using r-project.org> wrote:
>
> > Hi,
> >
> > ESS (version 16.10-1 but also earlier) gives the following indentation
> > for switch statements in r:
> >
> > f <- function(method = c("foo", "bar"))
> > {
> >     switch(match.arg(method),
> >            "foo" = { # (*)
> >         cat("Will use 'method' = \"foo\".\n")
> >     },
> >     "bar" = {
> >         cat("Will use 'method' = \"bar\".\n")
> >     },
> >     stop("Wrong 'method'"))
> > }
> >
> > Line (*) is not ideal. Looking over the various cases (in longer
> > switch statements) along column 4 (containing the "s" of "switch()"),
> > one can easily overlook the case "foo". The following would be great
> > to have:
> >
> > f <- function(method = c("foo", "bar"))
> > {
> >     switch(match.arg(method),
> >     "foo" = {
> >         cat("Will use 'method' = \"foo\".\n")
> >     },
> >     "bar" = {
> >         cat("Will use 'method' = \"bar\".\n")
> >     },
> >     stop("Wrong 'method'"))
> > }
> >
> > Is that possible?
>
> This is what I get when using the default style, FWIW.




More information about the ESS-help mailing list