A Change of Heart - RStudio to Atom
When I first started using RStudio I genuinely fell in love with R. The work that the RStudio community was able to do to build a reliable text editor that was tightly coupled with the R environment was a game changer. For that reason, I want to start with the following caveat. If you are still getting started with R, I strongly suggest using RStudio.
This post is intended to be a resource for people who are actively using multiple programming languages, and, specifically, those who are considering using Atom.
Getting Started with ATOM
The first step, installation, is fairly straightforward. The Atom Installation instructions are well described. The documentation is well written, in part (I suspect) because they have the resources and experience of the GitHub Team, who generally produce well written documentation for GitHub resources.
Atom has a number of packages that can be installed through the Command Palette:
If you want to look at the range of packages you can go to the Atom Packages webpage. On the Packages page you can see featured and trending packages, and search for packages you might be interested in. The Command Palette also allows you to modify themes, to give yourself a dark theme so you can look like a hacker.
Real programmers:— Citizen Jane (@metaknerd) May 29, 2018
✔️ Frontend Devs
✔️ Backend Devs
❌ People who use light-themed IDEs or Editors
Regardless, since using Atom there are a few packages I’ve found invaluable:
- Atom Beautify: A package to automatically format code (including Markdown), with support for a number of languages, including R (using Yihui Xie’s
- Markdown Preview: I do so much work in Markdown these days, as I develop my workflows, that having this tool built right into Atom is a real life-saver.
- Bracket Matcher: Honestly, do I need to explain why this is helpful? Especially as I move from general-purpose code to specific workflows that can handle the nested
foo()s that wind up cropping up to deal with edge cases, I find that a good bracket matcher is invaluable.
- atom-language-r: Helps support R in Atom, including code highlighting.
Getting Pipes with Keybindings
One of the things I missed the most about switching from
Atom was the fact that I couldn’t use
CTRL-SHIFT-M any more to get my beautiful
%>% pipes. I was resistant to pipes initially because I am always fighting my instinct to dislike anything new that I don’t discover for myself (Get off my lawn cool kids!).
Atom has support for various keybindings, some of these can be simple (for example Atom uses
CTRL-N for a new file, rather than RStudio’s
CTRL-SHIFT-N), but these keybindings can be customized. Very quickly, to add support to the editor to allow pipes, you need to modify two files:
- Edit the
init.coffeefile: To do this navigate to Edit > Init Script… A file called
init.coffeewill open up. This file interacts with the Atom API (a set of defined functions to interact with Atom) to generate user defined functions. I wrote one that looks like this:
atom.commands.add 'atom-text-editor', 'custom:piper', -> editor = atom.workspace.getActiveTextEditor() editor.insertText(' %>% ')
So, now, assocated with the text editor, there is a function we can refer to as
custom:piper. We’ll use this to link
custom:piper to the keybinding for
- Fix keybinding: Navigate to Edit > Keymap…. A new window will open up. Most of your attached packages have their own defined keymap bindings. Here you will define custom bindings that are your own. To do this, add the code:
'atom-text-editor': 'ctrl-shift-m': 'custom:piper'
Once you close and re-start Atom, you will have access to pipes using
ctrl-shift-m and some other great tools through your packages.