[TS EDITOR WARS] General thread for recommendations, discussion and tips on editors.

Dason

Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

I didn't even realize the first one was with an actual tab character which means it will display differently for different people. But that's why you shouldn't actually use tabs for alignment...

noetsi

No cake for spunky
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Does alignment matter in how the software calculates the results? I know in SAS it does not at all, but obviously this is not SAS.

Dason

Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

In python yes. In almost everything else - no. But alignment does make a difference in the readability of the code.

TheEcologist

Global Moderator
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Which is extremely important if you ask me. My older code is awful, and I hate myself for it

This a good read om how and why these things (that may seem nitpicky) are actually surprisingly important
(well maybe not the indentation examples above, but the readability point).

Best Practices for Scientific Computing

Abstract
Scientists spend an increasing amount of time building and u
sing software. However, most scientists are never taught how to d
o this efficiently. As a result, many are unaware of tools and practic
es that would allow them to write more reliable and maintainable cod
e with less effort. We describe a set of best practices for scientific
software development that have solid foundations in research and exp
erience, and that improve scientists’ productivity and the reliabil
ity of their software.

Dason

Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Typically when I run into code that has horrible indentation I toss it into Emacs and tell it to reindent the whole thing properly for me. This tends to make it A LOT easier to spot errors.

TheEcologist

Global Moderator
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Typically when I run into code that has horrible indentation I toss it into Emacs and tell it to reindent the whole thing properly for me. This tends to make it A LOT easier to spot errors.

Aaaaaaaah of course I didn't even think of this. Do you use the Good 'Ol

Code:
C+space M+shift+> C+i ?
That reminded me of an old XKCD (added to the intro post)

bryangoodrich

Probably A Mammal
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Trinker, the spacing and indents-as-spaces or indents-as-tabs are completely configurable in RStudio

Tools > Options > Code Editing
- Insert spaces for Tab
- Set tab width
- Vertically align arguments in auto-indent

I never did get what "enable vim editing mode" does lol

TheEcologist

Global Moderator
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Trinker, the spacing and indents-as-spaces or indents-as-tabs are completely configurable in RStudio
I never did get what "enable vim editing mode" does lol
You have VIM editing mode in RStudio?

noetsi

No cake for spunky
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

I hear the NSA search algorithms look for people who discuss how to improve formatting of code [something only a handful of people on the planet actually know about let alone care]. It is where they find some of the more dangerous people on the planet...

bryangoodrich

Probably A Mammal
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

You have VIM editing mode in RStudio?
Yes, and I don't know what it does, and I also don't know VIM anymore lol

Dason

Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Yes, and I don't know what it does, and I also don't know VIM anymore lol
It does pretty much what it sounds like... you edit in the source panel like you would in vim. I think it only offers normal (command) and insert modes though. So if you want to delete a line you can navigate to that line using j/k instead of up/down and then hit 'dd' to get rid of the line. If you want to add some text hit 'i' to enable insert mode and start typing away.

bryangoodrich

Probably A Mammal
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

You are a destroyer of hope :'(

Dason

Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

While that is true I don't see how it's related to me explaining the VIM mode?

trinker

ggplot2orBust
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

@BG that's my set up exactly. Here's what I don't like (and again it's preference).

Grab exactly this:

Code:
x <- c(44, 44, 44, 44, 44, 44, 44, 44, 44, 100)
Then put your cursor right before 100 and hit enter.

This is what it looks like:

Code:
x <- c(44, 44, 44, 44, 44, 44, 44, 44, 44,
100)
I'd prefer this:

Code:
x <- c(44, 44, 44, 44, 44, 44, 44, 44, 44,
100)
Which means I'd like to be able to hit enter and the 100 just goes to the begining of the line like this:

Code:
x <- c(44, 44, 44, 44, 44, 44, 44, 44, 44,
100)
And I'd hit space myself 4 times. I like it this way. it's like driving a standard transmission vs. and automatic. Some people like the flexibility of the standard. I'm one of them.

The auto indent here is nice for some. I want it to just return to the next line and let me put the number of spaces in that I feel are appropriate. As far as I can tell no set up in RStudio would have it auto indent as:

Code:
x <- c(44, 44, 44, 44, 44, 44, 44, 44, 44,
100)
So If I want this I have to hit enter, then delete the space RStudio felt was correct and I then hit spacebar 4 times myself.

This may seem silly but wen you have multiple lines as this:

Code:
x <- c(44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44,
100)
It looks like this in RStudio. This looks not as good to me and is wasteful of space and the problem is amplified if you use list instead of c.

Code:
x <- c(44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44,
100)

Dason

Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Once again I have to say that I just don't think you've taken the time to configure RStudio the way you want it. Really the fix is easy - uncheck the "Vertically align arguments in the auto-indent" box and you should have it do what you want.

bryangoodrich

Probably A Mammal
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Correction. Uncheck the "Vertically align arguments in auto-indent" box and it WILL do what he wants lol

But personally, a block assignment statement should go together, in my book. So something like

Code:
weeks <- c("Monday", "Tuesday",
"Wednday", "Thursday",
"Friday", "Saturday",
"Sunday")
is a good block statement. It's clear to see the group. If for some reason this is a really long start statement so the "name <- c(..." puts the block 20 spaces out or something, then I'd probably block them under the assignment line

Code:
# Not my first choice
weeks <-
c("Monday", "Tuesday",
"Wednday", "Thursday",
"Friday", "Saturday",
"Sunday"
)

# OR

weeks <- c(
"Monday", "Tuesday",
"Wednday", "Thursday",
"Friday", "Saturday",
"Sunday"
)
The trailing closing parenthesis may or may not add clarity. I usually don't do it these days, but it works like an opening closing brace in this case, and is common SQL programming (with the accompanying semicolon).

I usually use that last type of statement for non-assignment blocks, particularly functions or convoluted statements, because then your indent is less about blocking one entity (a single c(...) block) but grouping complexity (like a bracketed {...} clause).

Code:
foo <- lapply(foobar, function(x) {
... do stuff here ..
})
In fact, using the default (vertical auto-indent) it did exactly the above!

trinker

ggplot2orBust
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Here's a video view of my issue:

trinker

ggplot2orBust
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

@BG often I approach the formatting like you show, particularly when you have a list or are using a bracketed function inside lapply.

trinker

ggplot2orBust
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

Alright now that this thread has been thoroughly highjacked (Mods may want to break this off and I'll change my RStudio related con). The problem was fixed as Dason/Bg suggest and in the project I had opened the .Rproj actually was over riding the default options and that tab needed to be set to 4 as well.

vinux

Dark Knight
Re: [TS EDITOR WARS] General thread for recommendations, discussion and tips on edito

It is mainly for Emacs Users. Few good practices shared in this video