Setting Up Sublime Text with R
Info Notice: This page is currently under construction. Please check back in soon.
Introduction
Are you looking for an easy, fast, and flexible text editor, but aren’t sure where to start? Are you easily distracted and want all your files, programs, and projects in the same place? Do you want a editor than can handle a wide array of languages, programs, and platorms? If the answer to any of these questions is yes, then Sublime Text Editor is may be a great fit for you.
I first started using Sublime as a Political Science major in undergrad – and I had no clue what I was doing. Like many others, I had no experience with any sort of coding, and just thinking about mysterious lines on a screen made my head spin. And I wasn’t using it for python yet, only R and LaTeX. But within a short period of time, I was up and running.
In this post, let us walk through what Sublime is, why may be the right fit for you, and how to get it set up with R. In future posts, we will work through how to set it up with LaTeX, python, markdown, and much more!
But before we continue, I assume in this tutorial that you already have R dowloaded on your computers. If you have not, please do so here. For more information on R, check out their introduction here.
What is Sublime?
Sublime is a text editor. To be more specific, Sublime is a sophisticated, cross-platform source code editor. It supports a variety of programming and markup languages, and features an array of plugins, which are typically community-built and maintained under free-software licenses. You can think about Sublime as the swiss-army knife of text editing. The plugin ecosystem and its extensability make Sublime a worthy choice. It’s incredibly fast and lightweight. An annual subscription costs $99 USD, but note that the free trial period is unlimited.
While downloading Sublime is easy, setting it up to work with R, LaTeX, and other platforms is often less intuitive. But don’t be intimidated – it can be quite easy and straight forward. In the following sections, we will walk through setting up Sublime and installing the appropriate plugins. Note too, that for this tutorial, I will be demonstrating the examples for Windows, but I will provide additional information for Mac and Linux when possible.
Setting up Sublime
To download Sublime, follow this link to the Sublime webpage. Download the appropriate .exe file for your computer from the home page. Go ahead and run the executable file through the Setup Wizard that appears. If you want to save the program in a non-default location, this is when you can do it. Otherwise, you can keep hitting next and finally, install.
That’s it! You’ve successfully installed Sublime. Remember, if you are using the free unlimited trial, you may occasionally get a dialogue box prompting you to purchase a license, but if you wish to continue your trial, you can simply exit out of the box.
For the rest of this tutorial, we will be using the extension management system called ‘Package Control.’ This is used to install extensions, themes, and color schemes. Since Sublime does not come with Package Control, we will need to install it. To install anything, we need to first open the ‘Command Palette’. The shortcut for this is Ctrl + Shift + P (Command + Shift + P on Mac), although you can also open it from the Preferences tab. Using the shortcut, a toolbar will drop down from the top, and search ‘install.’ The first option should be `Install Package Control.’ Select it and hit Enter. It may take a minute.
After it is installed, I would recommend closing Sublime and re-opening it before we move to the next steps.
Setting up R with Sublime
Sublime can be an nice alternative to RStudio, especially when writing multi-format articles. While the visualizations may not be as immediately accessible (for instance, there is no variable viewer in the corner of the screen), it can also be less distracting. Further, all the data remains easily accessible, and when simulateously writing in LaTeX, everything is in the same application. Again, for someone with a short attention span, the less distractions the better.
To set up R with Sublime, we first need to install the appropriate packages. Again, open the Command Package and search ‘install.’ Now, ‘Package Controll: Install Package’ should be the first option. Select it and hit enter. This may take a moment.
From there, all the available repositories will be available to be chosen.
Now, we need to install the following packages:
- ‘SendCode’
- This sends code from the text editor to be run in either the terminal or in the R user interface (RGui). Select the option that says ‘SendCode: Choose Program’ and hit enter.
(As a note, you can set this part up a couple different ways. You can send the code directly to the R GUI, send it to a terminal, or some other shell. In this tutorial, we will be sending it to R’s interface, but know that there are options out there.)
Sublime will open a list of all the consoles where the code can be sent.
- ‘R-Box’
- This package is no longer maintained and has beens superceded by ‘sublime-ide-r’
- ‘R-IDE’
To make the appropriate path to R, go to ‘Preferences’ then ‘Package Settings’ at the bottom of the drop-down tab. From there, we can access all the settings for our downloaded packages. Find the one for R-IDE and open Settings.
Sending Code
Package Control
R-Box
sublime-ide-r: A package maintained by randy3k that transforms Sublime into R-Studio with some cool features added (formerly R-IDE).
SendCode: Send your code to a terminal or program such as Terminus/Terminal/R-GUI/R-Studio.
SublimeREPL