microsoft / RTVS

R Tools for Visual Studio.
MIT License
390 stars 118 forks source link

Indentation of nested functions aligns to the first function. #4296

Open nutterb opened 6 years ago

nutterb commented 6 years ago

I'm probably about to embarrass myself by describing something that's already been fixed, but here goes.

While setting up my editor I set RTools > Editor Options > R > Advanced > Smart indent > By function argument = On

When writing code I expected to see

# What I expected to see
library(dplyr)

mtcars %>%
  mutate(am = factor(am,
                     levels = 0:1,
                     labels = c("Automatic", "Manual")),
         vs = factor(vs,
                     labels = c("No", "Yes")))

But RTVS showed me something much less readable.

# What RTVS displayed
mtcars %>%
    mutate(am = factor(am,
    levels = 0:1,
    labels = c("Automatic", "Manual")),
    vs = factor(vs,
    labels = c("No", "Yes")))

Another example, when making a plot I would like to type

# What I expected to see
library(ggplot2)

ggplot(data = mtcars,
       mapping = aes(x = wt,
                     y = mpg)) +
  geom_point() +
  geom_line()

But RTVS displays

# WHAT RTVS Displayed
ggplot(data = mtcars,
       mapping = aes(x = wt,
       y = mpg)) +
       geom_point() +
       geom_line()

Notice that in this case, even after closing the parentheses for the ggplot function, the indentation still lines up strangely (seven spaces in front of geom_point instead of four). This is different behavior than if I put all of the ggplot argument on one line

# What it looks like in RTVS
ggplot(data = mtcars, mapping = aes(x = wt, y = mpg)) +
    geom_point() +
    geom_line()

If there's an option or configuration I'm missing, please let me know.

Similar issues

https://github.com/Microsoft/RTVS/issues/3751 https://github.com/Microsoft/RTVS/issues/2641 https://github.com/Microsoft/RTVS/issues/1004

codetrainee commented 6 years ago

Same issue here.

Microsoft Visual Studio Community 2017 Version 15.8.3 VisualStudio.15.Release/15.8.3+28010.2019 Microsoft .NET Framework Version 4.7.03056 R Tools for Visual Studio 1.3.40517.1016

Also smart indent in R markdown is disabled.

So much demanding features compared to Rstudio.